Importing Self

Denis S. Otkidach ods at fep.ru
Thu May 23 10:55:56 EDT 2002


On 22 May 2002, Salim Zayat wrote:

SZ> Hey there. I am running into a weird sort of problem.  I had
SZ> two
SZ> versions of the same tree-drawing code, a module to be used
SZ> by another
SZ> program.  I made some corrections to the second.  Now, for
SZ> some reason,
SZ> it is getting hung up in some stupid error.
SZ> I made a class named Error in my file.  In the first
SZ> version, I can
SZ> merely say :
SZ>
SZ> isinstance(e, Error)
SZ>
SZ> and it executes the statement fine.  However when I try the
SZ> same in the
SZ> second file, I get an Exception.  But, when I import the
SZ> module itself,
SZ> then say:
SZ>
SZ> isinstance(path.filename.Error)
SZ>
SZ> it works fine.  Why is this?  What are these sort of
SZ> problems indicituve of?

It looks like you have circular imports.  Circular imports are
bad thing, but circular "from module import *" are VERY BAD: they
cause "strange" NameErrors when you sure the name should be
imported from module.  Just change "from module import *" to
"from module import name1, name2, ..." to detect such problem.






More information about the Python-list mailing list