Import problem

David Allen s2mdalle at titan.vcu.edu
Wed Dec 20 05:24:23 CET 2000


I have a module that uses a particular object.  So
at the top of the file, I import that object.  But
for some reason, trying to create instances of that
object always fails with a NameError.  Here's the
error message:

Unhandled exception in thread:
Traceback (innermost last):
  File "./TkGui.py", line 285, in downloadThread
    contentKey = self.createContentFrame(request)
  File "./TkGui.py", line 350, in createContentFrame
    resp = conn.getResource(resource, self.messageBar)
  File "./GopherConnection.py", line 79, in getResource
    resp = GopherResponse()
NameError: GopherResponse

Now, to verify that I'm not smoking crack, here
are the first few lines of GopherConnection.py:

from GopherResponse      import *
from GopherResource      import *
from ResourceInformation import *

And just in case you think I'm crazy and that
GopherResponse isn't defined in GopherResponse.py,
here are the first few lines of that file:


from GopherObject        import *
from GopherResource      import *
from ResourceInformation import *

class GopherResponse(GopherObject):
	... code ...

So here's the issue - I'm importing a module, but
things in its namespace aren't coming in.

As far as I can come up with, the only idea I have
on why this might be happening is because many of
the objects use each other, so you get a situation
where many things import many other things, and you
may be getting a chicken and egg situation with
the importer.  But I thought python's importer was
brigher than that.

What else can cause this?  How is it that you can
from modulename import * and then NOT have access
to the things in that namespace?  Alternatively,
why does this case not work, when, say, I can use
module X in module Y and it works fine?  

Any help on figuring this out would be much appreciated.
-- 
David Allen
http://opop.nols.com/
----------------------------------------
It's 5:50 AM...do you know where your stack pointer is?



More information about the Python-list mailing list