which is best for a singleton, module or class?

Kragen Sitaker kragen at pobox.com
Sun Dec 2 04:42:48 EST 2001


hungjunglu at yahoo.com (Hung Jung Lu) writes:
> > hungjunglu at yahoo.com (Hung Jung Lu) writes:
> > > You can simply put your object into the __builtins__ namespace:
> 
> Joke? :) It's not a joke. Zope Corporation (the same *obnoxious*
> people that hired Guido, ha!) uses it. Experienced Python programmers
> do use this device, sparingly, but they do use it, in real life.

Well, the folks who wrote ZODB.Transaction (the one place in Zope that
uses it) have probably written more Python code than I have, and it's
certainly more widely used than my code.  But I still think this trick
is a bad idea, except when you're deliberately trying to write code
that's hard to understand.  What's wrong with

from ZODB import Transaction

Transaction.get()

Still, using this trick once in 150,000 lines of Python is not so bad;
there's only this one thing stuck into __builtins__, and it's used
about 150 times.




More information about the Python-list mailing list