Decorators and how they relate to Python - A little insight please!

Fuzzyman fuzzyman at
Sat Oct 21 23:57:48 CEST 2006

Fredrik Lundh wrote:
> Jerry wrote:
> > even though I've read the PEP
> even the examples section?

The second example of which shows :

Define a class with a singleton instance. Note that once the class
disappears enterprising programmers would have to be more creative to
create more instances. (From Shane Hathaway on python-dev.)

def singleton(cls):
    instances = {}
    def getinstance():
        if cls not in instances:
            instances[cls] = cls()
        return instances[cls]
    return getinstance

class MyClass:



> if you want more examples, see the cookbook
> </F>

More information about the Python-list mailing list