newbie: package and import problems
randy_shaffer at my-deja.com
randy_shaffer at my-deja.com
Fri Dec 3 14:22:03 EST 1999
The problem was a duplicate TestHarness directory in the system search
path. Sorry.
In article <828toe$dog$1 at nnrp1.deja.com>,
randy_shaffer at my-deja.com wrote:
> Hello. I'm experiencing an ImportError that I do not understand. I'm
> hoping someone can point out what I'm missing - thanks in advance.
>
> I have a package directory structure that looks like this:
>
> TestHarness/
> __init__.py
> THDatabase/
> __init__.py
> THUser.py
> THUniverse.py
>
> In THUser.py file, I have various class and function definitions
> including a top level test() function that excersizes all the code in
> the file. From the interpreter command line, I can type:
>
> >>> from TestHarness.THDatabase.THUser import *
> >>> test()
>
> Everything works just fine here. There is a problem when just
> executing the file stand-alone. The two lines I have in the file that
> I understand will enable this are the first:
>
> #!/usr/local/bin/python
>
> and the last:
>
> if __name__ == '__main__': test()
>
> The top few lines in the file look like this:
>
> import TestHarness
> import cPickle
> import os
> import string
> from TestHarness.THDatabase.THUniverse import KnownUniverse
>
> This last line causes the exception:
>
> ImportError: No module named THDatabase.THUniverse
>
> Why doesn't python see this file? The top level package name is known
> to sys.path.
>
> I can make this go away by including the lines:
>
> from TestHarness import *
> from THDatabase import *
> from THUniverse import *
>
> But then, in a statement buried in the THUniverse.py file I get an
> AttributeError for the variable TestHarness.RootDir. This is given a
> value in __init__.py in the top level package, TestHarness/.
>
> What am I doing wrong?
>
> Randy
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list