type vs. module (part2)

alex23 wuwei23 at gmail.com
Sun Oct 16 23:37:21 EDT 2011


On Oct 17, 9:11 am, Shane <gshanemil... at verizon.net> wrote:
> I now have two questions: How does Python allow two classes of the
> same
> type as evidenced by identical ``print type(<class>)' output and
> different id
> outputs?

You are looking at the id of two _instances_ of the class, not of the
class itself.

>>> class Example(object):
...   pass
...
>>> e1, e2 = Example(), Example()
>>> type(e1), type(e2)
(<class '__main__.Example'>, <class '__main__.Example'>)
>>> id(type(e1)), id(type(e2))
(20882000, 20882000)
>>> id(e1), id(e2)
(25931760, 25968816)

> Also, which module is t,t1 actually in? Is it "a.b.f"? Or is it
> "a.b.t.d".

Which module did you declare them in? What makes you think they're
defined somewhere other than what .__module__ is telling you?

My guess is your class is in a.b.f, your instances are created in
a.b.t.d, and you've demonstrated very powerfully the value of
meaningful names in code.

> I am totally confused.

And you have the source code. Imagine how we feel.



More information about the Python-list mailing list