Question regarding style/design..

Tim Chase python.list at tim.thechases.com
Fri Jul 17 19:11:49 CEST 2009


> Sometimes I see relatively small application, generally task scripts,
> written as essentially a list of statements. Other times, I see them neatly
> divided into functions and then the "if __name__ == '__main__':" convention.
> Is there a preference? Is there an... application scope such that the
> preference shifts from the former to the latter? I understand the use of the
> __name__ == 'main' convention for building unit tests, but I'm mixed on
> using it in scripts/small applications.

This may circle around to the "is Python a scripting language" 
bruhaha a while back.  I tend to skip the __name__ == '__main__' 
in what I'd consider scripts (one-file hacks to solve an 
immediate problem, often disposable or one-use wonders).  However 
for non-scripts (which I'd define as code that has more than one 
source-code file I've written or that I'd have to maintain) and 
for modules, I tend to put in the __name__ guard.

-tkc







More information about the Python-list mailing list