Extention to the integer class.

Gregoire Welraeds greg at perceval.be
Mon Mar 13 12:25:05 EST 2000


In reply to the message of Anthony J Wilkinson sent on Mar 14 (see below) :

> Alternatively you could use a __call__ method:
>         def __call__(self):
>             return self.__val

This works great. It also avoid to implement __cmp__() since i can do:
while i() < 2:
	...

Thanks too :)
--
Life is not fair
But the root password helps
--

Gregoire Welraeds
greg at perceval.be
Perceval Development team
-------------------------------------------------------------------------------
Perceval Technologies sa/nv	Tel: +32-2-6409194		
Rue Tenbosch, 9			Fax: +32-2-6403154		
B-1000 Brussels			general information:   info at perceval.net
BELGIUM				technical information: helpdesk at perceval.net
URL: http://www.perceval.be/
-------------------------------------------------------------------------------

On Tue, 14 Mar 2000, Anthony J Wilkinson wrote:

> Date: Tue, 14 Mar 2000 01:47:01 +1000 (EST)
> From: Anthony J Wilkinson <anthony at dstc.edu.au>
> To: python-list at python.org
> Subject: Re: Extention to the integer class.
> 
> 
> Gregoire Welraeds wrote:
> 
> > class Int:
> 
> [...]
> 
> > But It fails when i use i as an index in a list ex: list[i]
> > I could create a get method :
> >         def get(self):
> >                 return self.__val
> > but it is very poor since each time i is a index, i have to write i.get().
> > ex: list[i.get]
> 
> 
> You could also create a __int__ method:
>         def __int__(self):
>             return self.__val
> 
> which would be used as: list[int(i)]
> 
> Alternatively you could use a __call__ method:
>         def __call__(self):
>             return self.__val
> 
> which would be used as: list[i()]
> 
> Java has similar problems with a mix of 'primitive' types (ints, chars,
> doubles, etc) and instance types. It makes a lot of java very ugly - I
> recently had to write:
> 
> cost = Integer.valueOf(costString.trim()).intValue();
> 
> which is equivalent to the python:
> 
> cost = int(costString)
> 
> So it seems to me that python handles these things a little better than
> Java does.
> 
> Anthony
> 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 
> 





More information about the Python-list mailing list