Organizing Python

s713221 at student.gu.edu.au s713221 at student.gu.edu.au
Tue Mar 20 01:04:05 CET 2001


> from the module foo. A module is usually represented by a file, but it
> is also possible to have it be a directory which I once read something
> about on python.org, but I can't find it now. 

If you place a file called __init__ into a directory on your path,
python imports that as the name of the directory.

/python/path/FFT
		|
		----->__init__.py #contains python instructions to load code from
other
		|		files
		|
		----->other/files/and/directories which make up FFT

>>>import FFT	#Imports FFT/__init__.py
>>>print "Handy, ain't it?"

Another method is to put a file called module_name.pth into your python
path, containing the name of a directory that the module is in. (What
I've used to get Numeric working without fiddling with my /etc/profile
or ~/.bashrc files.).

less /usr/lib/python2.0/site-packages/Numeric.pth

Numeric

In this case, python loads the file with the name of the module

/usr/lib/python2.0/site-packages/Numeric
					|
					----> Numeric.py
					|
					----> other numeric files

>>>import Numeric	# Imports Numeric/Numeric.py
>>>print "A little bit messier, but maybe what the original poster was looking for?"

Joal Heagney/AncientHart

Joal Heagney/AncientHart



More information about the Python-list mailing list