newbie question

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Nov 27 21:25:52 EST 2008


On Thu, 27 Nov 2008 17:58:55 -0800, Asun Friere wrote:


> if __name__ == '__main__' :
>     import sys
>     sys.exit(main(sys.argv))
> 
> Doesn't this just pollute the namespace with main()?

Agreed. I don't see anything wrong with that. You have one function more 
than you otherwise would have had, and you get the benefit that after 
importing the module, you can say module.main(myargs) to run the code 
just as if you had run it from the command line.

In other words... in my opinion, writing a non-trivial main() function is 
the right thing to do.


-- 
Steven



More information about the Python-list mailing list