property getter with more than 1 argument?

mk mrkafk at gmail.com
Thu Jul 17 10:57:08 EDT 2008


It seems like getter is defined in such way that it passes only 'self':


class FunDict(dict):
	def __init__(self):
		self.fundict = dict()

	def fget(self, fun):
		return fundict[fun.func_name]

	def fset(self, newfun):
		self.fundict[newfun.func_name] = newfun

	newfun = property (fget, fset)

	
 >>> a=FunDict()
 >>>
 >>> a.newfun=f1
 >>>
 >>> a.newfun('f1')

Traceback (most recent call last):
   File "<pyshell#67>", line 1, in <module>
     a.newfun('f1')
TypeError: fget() takes exactly 2 arguments (1 given)



Is it possible to pass more than one argument to fget function?

I know: I can define a function with property name ('newfun' in the 
example) and call it with more arguments. But then I do not get the 
benefits of setter and property in general!




More information about the Python-list mailing list