3 ms·
if __name__ == '__main__': run() Am I the only one who thinks that this is just plain horrible? It's incomprehensible voodoo.
by bartl 17y ago
if __name__ == '__main__':
run()
Am I the only one who thinks that this is just plain horrible? It's incomprehensible voodoo.
- pyre 17y agoBy the same token, I could look at (any) Ruby code and call it the same thing seeing as it is a far enough deviation from 'C-like' languages and I haven't bothered to learn it yet. The "if __name__= '__main__':" convention is pretty well-established in Python. __name__ is only '__main__' when the script is the 'main' script being run (i.e. it wasn't imported as a module/package).
- csytan 17y agoThis is commonly used in python modules which can also be run by command line. http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm I do agree though, it would be better to remove the if statement altogether since it's unlikely to be imported as a module.
- deleted 17y ago[deleted]
- the_mitsuhiko 17y agoWell, the run() function was intended to be a very bad example of API. Because there is that magical application object you never see that run magically picks up. There is another example of really bad API in denied: there is a template render function internally (you have to read the code behind the code to see that) which magically accepts both filenames for templates and template source strings. And there are a couple of more examples of really, really bad ideas in that code.