[Tutor] Need help with a couple of concepts

William Park parkw@better.net
Fri, 3 Mar 2000 14:45:39 -0500


On Fri, Mar 03, 2000 at 02:13:24PM -0500, Robin B. Lake wrote:
> 1.  Am modifying some code.  There is at the bottom:
> 
> if __name__ == '__main__':
> 	main()
> 
> and after the imports:
> 
> def main():
> 
> What is this all about?

If you call this module from command line, like
    $ python <whatever>.py
then, '__name__' variable will be '__main__' string.  But, if you import
into another module or program, then '__name__' variable will be its
module name.  By testing for how it was called, you can run 'main()'
routine regardless.


> 2.  I have some code from a Python book that requires the kjbuckets
> extension module.  I've downloaded the kjbuckets module.  Where in
> the Mac directory tree should I put it so that Python will find it
> when needed?

Proper ways are
    - set 'PYTHONPATH=...'
    - install under "site-python" directory which usually is at the same
      level as standard "python1.5".
To find out the standard path,
    >>> import sys
    >>> sys.path

--William