property problems

Mike C. Fletcher mcfletch at rogers.com
Wed Nov 13 18:50:05 EST 2002


Okay, there's a number of things going on here:

    * properties only work (properly) with new-style classes, new-style
      classes derive from other new-style classes, normally "object".
       Your class GlobalVars is an old-style class.  Derive from object
      to prevent problems which _will_ come up later on.
    * you are accessing a property which stores a list as if it was the
      setter method of that property.  You want to do:

        gv.stats =
        [['Height',self.height],['Build',self.build],['Strength',str]]

    * gv.stats( ... ) is actually accessing the property value, which is
      currently a list object, and then trying to call it as if it were
      a function/method/callable object (it isn't one).

HTH,
Mike

Newt wrote:

> Hi,
>  
> I've got a problem trying to use a property in a class module. The 
> class module is listed below (it's called globals.py):
>  
> class GlobalVars:
>  
>     def __init__(self):
>         self.l_stats = []
>         return
>  
>     def set_stats(self,val):
>         self.l_stats = val[:]
>         return
>  
>     def get_stats(self):
>         return self.l_stats
>  
>     stats = property(get_stats, set_stats)
> gv = GlobalVars()
>  
> I've got a further module which does the following:
>  
> from globals import gv
> gv.stats([['Height',self.height],['Build',self.build],['Strength',str]])
> However, I get the following error:
>  
> Exception in Tkinter callback
> Traceback (most recent call last):
>   File "C:\Python22\lib\lib-tk\Tkinter.py", line 1292, in __call__
>     return apply(self.func, args)
>   File "D:\py_stuff\curry.py", line 14, in __call__
>     return self.fun(*(self.pending + args), **kw)
>   File "D:\py_stuff\chaz.py", line 223, in shownext
>     SelectStats(self)
>   File "D:\py_stuff\stats.py", line 46, in __init__
>     self.do_widgets()
>   File "D:\py_stuff\stats.py", line 208, in do_widgets
>     
> gv.stats([['Height',self.height],['Build',self.build],['Strength',str]])
> TypeError: 'list' object is not callable
>  
> Could somebody explain to mw what this means, and how to fix it please!
>  
> Thanks,
>  
> Newt


-- 
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/







More information about the Python-list mailing list