Huh?!?!? What is it that I'm seeing here?

Tobiah toby at rcsreg.com
Sun Sep 14 17:54:11 EDT 2003


> performing properly (albeit somewhat inefficiently, since I haven't done 
> any tweaking yet) but one particular construct has me stumped. It looks 
> like this:
> 
> if __name__ == '__main__':
>   run(argv[1:])
> 

This is used to check whether the script file is being
run directly as a python script (as opposed to being
imported as a module).

One use of this is to put unit tests in each module filed.
Then you can just do "python module.py" to run the code
under the if statement.  When you import the module, the
test code will not be run.

Tobiah





More information about the Python-list mailing list