addvalue, how do i implement the code?

Emile van Sebille emile at fenx.com
Wed May 17 11:40:52 EDT 2000


I'm not sure exactly what you're after,
but name/value pairs probably want to be
in a dictionary structure.

Also, the way it looks like you want to
invoke this is addressed with __call__:

class addv:
    def __call__(self,x,y):
        return x + y

test = addv()
print test(3,4)

HTH,

Emile van Sebille
emile at fenx.com
-------------------


----- Original Message -----
From: Shaun <shogan at iel.ie>
To: python <python-list at cwi.nl>
Sent: Wednesday, May 17, 2000 8:10 AM
Subject: addvalue, how do i implement the code?


>
> 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
>
>
>
>
>
> --
> http://www.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list