[Tutor] How to import my own module

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Tue, 25 Sep 2001 15:19:56 -0700 (PDT)


On Tue, 25 Sep 2001, runsun wrote:

> How can I import my own module and use the
> functions/classes/variables that are defined in
> that module ?
> 
> Should I put it in the /usr/local/bin/python folder?
> Should I be a root in order to do so ? Or I can put
> it in the same folder in which the calling cgi resides?

It depends; if you want everyone on your system to be able to easily
access your module, putting it in the site-packages directory as Ignacio
suggests is a good choice.  You'll probably need to be root to move the
files there.

Putting the file in the same directory as the calling CGI will also work,
and is probably a very good choice for CGI programs.


If your module is for more personal use, you can also stuff it in a
private directory, and add that directory to your PYTHONPATH environment
variable.  I don't know how much experience you have in the Unix
environment, but if you'd like an example, I can cook one up.  This
approach may not be suitable for CGI's, but they're quite nice for one's
own personal library.

Good luck to you!