property getter with more than 1 argument?

Roy H. Han starsareblueandfaraway at gmail.com
Thu Jul 17 13:32:13 EDT 2008


I don't understand what you're trying to do here.


On Thu, Jul 17, 2008 at 10:57 AM, mk <mrkafk at gmail.com> wrote:
>
> 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!
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list