[Tutor] Module search path problem
Bob Gailer
bgailer at alum.rpi.edu
Tue Feb 27 17:49:14 CET 2007
Christer Enfors wrote:
> I have two files, in the same directory: main.py, and user.py I have the
> following code in main.py:
>
> ----main.py----
> import user
>
> [snip]
>
> user_man = user.UserMan()
> -----end-----
>
> This works without problems.
>
> But then I tried moving user.py to a subdirectory, and adding that
> directory to Python's module search path, so this is what main.py looks
> like now:
>
> ----main.py---
> import sys
> sys.path.append("/correct/complete/path/to/subdir")
>
> import user # Generates no error message, so it's finding user.py
>
> [snip]
>
> user_man = user.UserMan()
> -----end-----
>
> But now I get an error message for the last line shown above:
>
> ----start----
> Traceback (most recent call last):
> File "./main.py", line 56, in ?
> driver.boot()
> File "./main.py", line 34, in boot
> user_man = user.UserMan()
> AttributeError: 'module' object has no attribute 'UserMan'
> -----end-----
>
> What's up with this?
>
Kent gave the answer for this case. In general use the __file__
attribute of the module object to see what was actually imported. In
your case:
print user.__file__
--
Bob Gailer
510-978-4454
More information about the Tutor
mailing list