addvalue, how do i implement the code?

Shaun shogan at iel.ie
Wed May 17 11:10:00 EDT 2000


right lads heres what im trying todo:
i make an empty list, (start=[])
what i want to do is then add a name value pair say...('shaun',20)
to the empty list,
ive got a feeling the code looks somthing like what below but im not sure
how to implement it can any of yous help me out on that one?
Shaun

>>> class addv:
    def add(self,x,y):
        print'does not print'
    def __init__(self,start=[]):
        self.data=start
    def __add__(self,other):
        return addv(self.data, other)

>>> addv
<class __console__.addv at 10486e0>
>>> x=addv.add
>>> x
<unbound method addv.add>
>>> x(3,4)
Traceback (innermost last):
  File "<pyshell#4>", line 1, in ?
    x(3,4)
TypeError: unbound method must be called with class instance 1st argument
>>>
=====================
Shaun Hogan
Interactive Enterprise Ltd.
alt. E-mail : shaun_hogan at yahoo.com
Phone: +353 86 8342529

The University of Limerick Rollerhockey Club
URL: http://rollerhockey.csn.ul.ie








More information about the Python-list mailing list