isinstance() not recognizing an instance correctly (python bug?)

Martin v. Löwis loewis at informatik.hu-berlin.de
Wed May 8 05:41:04 EDT 2002


Fernando Perez <fperez528 at yahoo.com> writes:

> So both the user-defined one and the internal one have been imported
> via the same statement. Note however that as I said, the interactive
> user code is run in a closed namespace, which is what (I think)
> causes the behavior. I could well be confused though.

I guess you need to explain in more detail what a "closed namespace"
is. Does it share sys.modules with the rest of the interpreter?

If not, that would indeed explain the problem.

You should compute and print the id of class Struct at both places,
and see whether they are identical. If not, it is not surprising that
the isinstance check fails - you would have two different classes that
just happen to have the same name.

Regards,
Martin



More information about the Python-list mailing list