[Python-Dev] PEP 318 - posting draft (original) (raw)
Guido van Rossum guido at python.org
Wed Mar 24 13:32:04 EST 2004
- Previous message: [Python-Dev] PEP 318 - posting draft
- Next message: [Python-Dev] PEP 318 - posting draft
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>> I think this use case is rather elegant: >> >> def singleton(cls): >> return cls() >> >> class Foo [singleton]: >> ...
Guido> And how would this be better than Guido> class Foo(singleton): Guido> ... Guido> (with a suitable definition of singleton, which could just be Guido> 'object' AFAICT from your example)? "Better"? I don't know. Certainly different. In the former, Foo gets bound to a class instance. In the latter, it would be a separate step which you omitted: class Foo(singleton): ... Foo = Foo()
Ok, so the metaclass would have to be a little different, but this can be done with metaclasses. (But I think that this in particular example, declaring the instance through the class is merely confusing. :-)
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] PEP 318 - posting draft
- Next message: [Python-Dev] PEP 318 - posting draft
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]