import error?

Peter Hansen peter at engcorp.com
Thu Oct 16 09:52:19 EDT 2003


Tom wrote:
> 
> Peter Hansen wrote:
> 
> >Is there a complete trackback you could post?  Then nobody would
> >have to guess what your problem is.
> >
> Traceback (most recent call last):
>   File "<string>", line 1, in ?
>   File "C:\Test\TestAnaMod.py", line 103, in ?
>     mul.multi(ActualState, Data, d, BoundModels, Automat, LogName)
>   File "C:\Test\multi_C.py", line 102, in multi
>     ReIni = initialize_C()
> NameError: global name 'initialize_C' is not defined
> 
> At the very beginning of the module I include the other module which has
> the class  initialize_C. This is not the only time I refere to another
> module and its class and functions. But it is the only time I get an
> error. But I have no typos in the code. Strangewise I can call the
> module with the class initialize_C from another module without causing
> any problems!??! The weird thing is, that I have this at the beginning
> of my module "from IniMod import *" (this is the module that has the
> class initialize_C) and it doesn't work. But if I cut this line and
> paste it into line 101, it works perfectly. Why is that? If I include it
> at the very beginning of my module, shouldn't it be valid for the entire
> module? If I import the module in line 101 I get this little warning
> saying that I should import this at the beginning of the module, but it
> works at least. :-)
> 
> I hope this helps to clear things up and you guys can help me. I am
> quite confused right now.

We're now as confused as you are, but only because you aren't including
enough clear details to make the answer obvious yet...

You say "at the beginning of the module"... _what_ module?  The above
example seems to be one that you got by typing things at the interactive
interpreter.  Otherwise I would expect to see file names and not "?"
and <string> in the traceback.

You talk about the "other module" (which one?) with initialize_C, but the 
code above has code that is trying to call initialize_C() without 
prefixing the name with the name of the module where initialize_C is
defined.  Presumably therefore it is supposed to be defined in IniMod,
which you claim to have imported first in multi_C.py, but that simply
cannot be or you would not get that traceback.

Is it possible that you did the "from IniMod import *" in the file
TestAnaMod.py, but not in the file multi_C.py?  In that case the 
problem is simply that you didn't actually tell multi_C.py where
to find the initialize_C() class... you can't expect one import
statement to apply to all modules automatically like that.

Without a better picture of the layout of your functions and modules,
I can't help more.

By the way, don't get caught up in the "works on line 101" sort of
thing.  The answer will be very simple once you find it, not some
strange bug relating to having things above or below something 
else but only on Tuesdays. :-)

-Peter




More information about the Python-list mailing list