Classes and modules are singletons?

Aahz aahz at pythoncraft.com
Thu Mar 6 16:24:47 EST 2008


In article <13sulsu4nbr2199 at corp.supernews.com>,
Steven D'Aprano  <steve at REMOVE-THIS-cybersource.com.au> wrote:
>
>I accept my question about classes being singletons is not well-formed, 
>not even in my own mind. I guess one way of asking is, for any two class 
>objects (not instances) C1 and C2, does "C1 == C2" imply "C1 is C2"?

Even that stricture fails under the presence of metaclasses.  ;-)  But
answering your real question, I don't remember off-hand the required
sequence, but it is possible to import a class two different ways such
that the classes are not the object.  This can cause problems with e.g.
pickle.  Within a single module, given a class defined only once within
that module, the class will be a singleton.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of     
indirection."  --Butler Lampson



More information about the Python-list mailing list