Controlling assignation
egbert
egbert.bouwman at hccnet.nl
Mon Jun 13 10:54:17 EDT 2005
On Mon, Jun 13, 2005 at 03:52:14PM +0200, Xavier Décoret wrote:
> In other word, I would like to be able to use a=5 instead of a.set(5)
If a(5) is acceptable to you in stead of a=5
you can make your instance callable with the __call__ method:
class A(object):
def __init__(self):
self.var=0
def __call__(self,val=None):
self.var=val
a = A()
a(5)
print a.var # gives 5
egbert
--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991
========================================================================
More information about the Python-list
mailing list