importing a user file in Python

Rick Dooling rpdooling at gmail.com
Sat Dec 1 07:45:51 EST 2007


On Dec 1, 1:42 am, waltbrad <waltb... at hotmail.com> wrote:

> Hello. I'm brand new to Python.
>
> Where on my system do I have to place these files before the
> interpreter will import them?
>

In this case, odbchelper.py is a module you are trying to import.

http://docs.python.org/tut/node8.html

One suggestion is to make a directory in your /home dir where you keep
your downloaded and homemade Python modules and scripts. I call mine
"Python" so it's ~/Python or /home/rick/Python.

Then, as suggested, add this dir to your Python path, so that you can
import your custom modules (with import odbchelper).

You may also want to add that dir to your system path, so that you can
call your Python scripts from anywhere without having to change back
to the ~/Python directory:

export PATH=~/Python:~/bin:$PATH

Here I've added two directories: Python and bin to $Path so that the
system knows to look for executables there.

Good luck.

Rick



More information about the Python-list mailing list