[Python-Dev] Class decorators (original) (raw)
Jim Jewett jimjjewett at gmail.com
Sat Apr 1 00:01:54 CEST 2006
- Next message: [Python-Dev] Class decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nick Coghlan wrote:
[ much good, including the @instance decorator ]
P.S. If all you want is somewhere to store mutable state between invocations, you can always use the function's own attribute space
>>> def f(): print "Hi world from %s!" % f
>>> f()
Hi world from <function f at 0x00AE90B0>!
Not really. That assumes the expected name is (permanently) bound to this function in this function's globals. That's normally true, but not always, so relying on it seems wrong.
>>> f="a string"
>>> g()
Hi world from a string!
And of course, sometimes I really do want shared state, or helpers (like other methods on a class), or one-time ininitialization plus per-call parameters (like the send method on 2.5 generators), or ...
-jJ
- Next message: [Python-Dev] Class decorators
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]