Torsten Marek wrote: > Maybe I'm spoiled from programming too much Java in the last year, but
Hmm. Would that be spoil 3 a: to damage seriously : ruin or spoil 4 b: to pamper excessively : coddle ? ;-) > IMHO it's a good idea to put the singleton instance into the class > itself rather than into some module. > > This way, you (can) make sure that all accesses to the class really go > to the same instance. This is not needed in Python, module-level variables are essentially singletons. > There are, of course, many ways to do that, but I'd prefer a method on > the class: > > class Foo(object): > @classmethod > def instance(cls): > try: > return cls._inst > except AttributeError: > cls._inst = Foo() > return cls._inst Yikes! Looks like 3a to me! How is this safer than having a single global instance? Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor