[Tutor] adding a new folder to Python's importable modules search path

tpc247 at gmail.com tpc247 at gmail.com
Mon Nov 26 23:17:07 CET 2007

hey guys, thanks a lot for your insight (or lack thereof) which convinced me
to try further investigation on what I might have left out.  One significant
point of correction: for purposes of simplification, I neglected to include
for your review the fact that when I attempted to add my path to Python's
importable modules search path, I did the following:

import os
import sys

folder_1 = os.path.join('x', 'y', 'z', 'w', 's')
folder_2 = os.path.join('x', 'y', 'z', 't', 'm', 'n', 'a', 'b', 'c', 'd')
folders = [folder_1, folder_2]

for a_path in folders:
    sys.path.append(os.path.join("F://", a_path) + os.sep)

import My_Module

ImportError: No module named TableParse

sys.path.append(os.path.join("F://", folder_1) + os.sep)
sys.path.append(os.path.join("F://", folder_2) + os.sep)

import My_Module

ImportError: No module named TableParse

apparently the interpreter does not like the os.sep at the end of the search
path.  Once I removed it, everything was gravy.

On 11/26/07, Dave Kuhlman <dkuhlman at rexx.com> wrote:
> On Sun, Nov 25, 2007 at 11:14:47PM -0800, Jeff Younker wrote:
> >
> > > so when I run my script from the command line, the folder does seem
> > > to be added to Python's importable modules search path.  When I
> > > attempt to import my_module I get the error:
> > >
> > > ImportError: No module named my_module
> >
> > Do your module directories have an __init__.py file
> > in them?
> Actually, you do not need an __init__.py file in directories that
> are immediately in sys.path.  You *do* need that __init__.py file
> in sub-directories (which you access via dot notation).  See:
>     http://docs.python.org/ref/import.html  (and search for __init__)
> Dave
> --
> Dave Kuhlman
> http://www.rexx.com/~dkuhlman
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071126/c5dcac93/attachment.htm 

More information about the Tutor mailing list