Imported or executed?

Jeff Shannon jeff at ccvcorp.com
Wed Feb 16 14:23:33 EST 2005


Stephan Schulz wrote:

> Is there a (portable, standard) way for the program/module to find out
> if it is imported or executed stand-alone?

def fixbb(*filelist):
     # ...

if __name__ == '__main__':
     # Executed stand-alone
     fixbb(sys.argv[1:])

(Obviously, you'd probably want to do more command-line checking than 
this...)

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list