Question about 'if __name__ == "__main__":'

Mirko Zeibig mirko-lists at zeibig.net
Tue Feb 3 07:23:44 EST 2004


Hakan Nilsson said the following on 02/03/2004 09:57 AM:
> On Tue, 3 Feb 2004, PoD wrote:
> 
> 
>>On Mon, 02 Feb 2004 23:33:42 -0800, Amy G wrote:
>>
>>
>>>I have a program that needs a little help.
>>>Right now the program runs in my crontab.  When it runs, it sets a few
>>>variables based on a query to a MySQL database.  I would like to modify it
>>>so that it can run as it is... or if arguments are supplied, use those
>>>instead of querrying the database.
>>>
>>
>>Hint: len(sys.argv)
>> 
> 
> You might want to check out the getopt module too:
> 
> http://www.python.org/doc/current/lib/module-getopt.html
> 
> Depends on how many arguments you are planning to support I guess.

Or if you are using Python-2.3 go for:
http://www.python.org/doc/current/lib/module-optparse.html

It is available as seperate package (http://optik.sf.net) for older 
versions as well.

Regards
Mirko



More information about the Python-list mailing list