News for hackers. Stuff that matters.
Re:Denied: Python Micro-Framework (Sinatra-like) by bartl on Friday April 02, 2010 @05:22PM (#1237615)

    if __name__ == '__main__':
        run()
Am I the only one who thinks that this is just plain horrible? It's incomprehensible voodoo.
Re:Denied: Python Micro-Framework (Sinatra-like) by csytan on Friday April 02, 2010 @05:28PM (#1237624)
This 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

I do agree though, it would be better to remove the if statement altogether since it's unlikely to be imported as a module.

Re:Denied: Python Micro-Framework (Sinatra-like) by the_mitsuhiko on Friday April 02, 2010 @05:55PM (#1237680)
Well, 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.

Re:Denied: Python Micro-Framework (Sinatra-like) by pyre on Friday April 02, 2010 @07:01PM (#1237792)
By 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).