On Tue, Jul 19, 2005 at 07:56:20PM +0300, Thanos Tsouanas wrote: > Hello. > > (How) can I have a class property d, such that d['foo'] = 'bar' will run > a certain function of the class with 'foo' and 'bar' as it's arguments?
You could implement a custom container type that will do what you want. See http://docs.python.org/ref/sequence-types.html for __setitem__. Quick hack: >>> class Foo: ... def __init__(self): ... self.d = self ... def __setitem__(self, key, value): ... getattr(self, key)(value) ... def bar(self, param): ... print "bar got called with", param ... >>> foo = Foo() >>> foo.d["bar"] = 42 bar got called with 42 >>> -- Gerhard -- Gerhard Häring - [EMAIL PROTECTED] - Python, web & database development
signature.asc
Description: Digital signature
-- http://mail.python.org/mailman/listinfo/python-list