[Tutor] How do you make a module
Sean 'Shaleh' Perry
shalehperry@attbi.com
Tue, 16 Apr 2002 21:35:45 -0700 (PDT)
>
> Thanks. I didn't realize that even the program calling other modules was in
> fact a module itself.
>
when used as a module the value of __name__ is the name of the module file,
when ran by the interpreter it is '__main__'. This is why you see code like
this:
foo.py:
def foo():
do stuff
if __name__ == '__main__':
# test foo out
#end
if I then do:
import foo
foo.foo() it is happy. If I do python foo.py it will run the tests.