Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: seems like a bug in isinstance() Date: Sat, 07 May 2011 20:53:40 +1200 Lines: 32 Message-ID: <92kfkmF4d5U1@mid.individual.net> References: <15501b92-9392-45d4-a337-c4064a237813@w36g2000vbi.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 0lu11c6hEtvcYmwNfwuvvQA+NqhMuzEGCG7axixf6nppyCuhYh Cancel-Lock: sha1:wmsKYbiZpgsRJfDFQNEQiyiuCzI= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4892 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