Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4892
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: seems like a bug in isinstance() |
| Date | 2011-05-07 20:53 +1200 |
| Message-ID | <92kfkmF4d5U1@mid.individual.net> (permalink) |
| References | <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> <mailman.1231.1304675862.9059.python-list@python.org> |
Chris Rebert wrote: > This is because you did `from Point import > ...` in file2.py, whereas in file1.py you did `from > openopt.kernel.Point import ...`. These 2 different ways of referring > to the same module are sufficient to "trick"/"outsmart" (C)Python and > cause it to import the same module twice That can't be the whole story, because those two ways of referring to the module *should* have returned the same module object, even though one is absolute and the other relative. I suspect what's happened is that somehow sys.path contains both the directory containing .../openopt *and* the directory .../openopt/kernel, and the second import is picking up Point.py a second time as though it were a top-level module. This could have happened by starting an interactive session while cd'ed to .../openopt/kernel, or by launching a .py file from there as a main script. The solution is to make sure that sys.path only contains the top level directories of the package hierarchy, and doesn't also contain any of their subdirectories. Always using absolute imports may be a good idea stylistically, but in this case it will only mask the symptoms of whatever is really wrong, and further problems could result from the same cause. -- Greg
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
seems like a bug in isinstance() dmitrey <dmitrey15@gmail.com> - 2011-05-06 02:24 -0700
Re: seems like a bug in isinstance() Chris Rebert <clp2@rebertia.com> - 2011-05-06 02:57 -0700
Re: seems like a bug in isinstance() dmitrey <dmitrey15@gmail.com> - 2011-05-06 03:20 -0700
Re: seems like a bug in isinstance() Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-06 11:27 -0600
Re: seems like a bug in isinstance() Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-07 20:53 +1200
Re: seems like a bug in isinstance() dmitrey <dmitrey15@gmail.com> - 2011-05-07 03:04 -0700
Re: seems like a bug in isinstance() Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-08 10:58 +1200
csiph-web