Fredrik Lundh wrote:
> Jerry wrote:
>
> > even though I've read the PEP
>
> even the examples section?
>
>      http://www.python.org/dev/peps/pep-0318/#examples
>

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

@singleton
class MyClass:
    ...


:-o

Fuzzyman
http://www.voidspace.org.uk/


> if you want more examples, see the cookbook
>
> http://www.google.com/search?q=+site%3Aaspn.activestate.com+decorator+cookbook
> 
> </F>

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to