2. Re: Python interface problem with Windows (Benjamin Kaplan)

rantingrick rantingrick at gmail.com
Sun Jun 27 07:11:03 EDT 2010


On Jun 27, 5:52 am, Kermit Rose <ker... at polaris.net> wrote:
> On 6/26/2010 9:30 PM, python-list-requ... at python.org wrote:

> I do not know how to import code from any other directory than the
> default, C:\Python26.

Kermit,

There are a couple of ways to import python modules from various
places. But first create a folder somewhere (like was mentioned
earlier) to keep all your personal modules and scripts in. Now create
a file named "myconfig.pth" and throw it in your main PythonXX folder.
Any paths in this file will be added to the search path of Python
modules. Now you can import from these folders

Also so you will be aware. You can add folders to the python search
path by appending or inserting to the sys.path array.

>>> import sys
>>> print sys.path
[...list of paths here...]
>>> sys.path.append('path\to\some\directory\containing\script.py')
>>> import script.py

There are other ways...



More information about the Python-list mailing list