Re: deriving from float or int

2006-02-21 Thread Robert Kern
gene tani wrote: > Russ wrote: > >>Does it ever make sense to derive a class from a basic type such as >>float or int? Suppose, for example, that I want to create a class for >>physical scalars with units. I thought about deriving from float, then >>adding the units. I played around with it a bit,

Re: deriving from float or int

2006-02-21 Thread gene tani
Russ wrote: > Does it ever make sense to derive a class from a basic type such as > float or int? Suppose, for example, that I want to create a class for > physical scalars with units. I thought about deriving from float, then > adding the units. I played around with it a bit, but it doesn't seem

Re: deriving from float or int

2006-02-21 Thread Terry Hancock
On Tue, 21 Feb 2006 15:01:22 -0600 Robert Kern <[EMAIL PROTECTED]> wrote: > http://www.python.org/2.2.3/descrintro.html#__new__ Curiously, __new__ does not appear in the index of the Python 2.3 language reference! It is fixed in Python 2.4, though -- I just checked. -- Terry Hancock ([EMAIL PRO

Re: deriving from float or int

2006-02-21 Thread Sybren Stuvel
Russ enlightened us with: > The problem is that when I derive a new class from float, the darn > thing won't let me create a constructor that accepts more than one > argument. Use __new__, not __init__. It's the function that's called when a new immutable object is created. Sybren -- The problem

Re: deriving from float or int

2006-02-21 Thread Robert Kern
Russ wrote: > The problem is that when I derive a new class from float, the darn > thing won't let me create a constructor that accepts more than one > argument. I need two arguments: one for the numerical value and one for > the units. But when I try to give the constructor two arguments, I get >

Re: deriving from float or int

2006-02-21 Thread Russ
The problem is that when I derive a new class from float, the darn thing won't let me create a constructor that accepts more than one argument. I need two arguments: one for the numerical value and one for the units. But when I try to give the constructor two arguments, I get this when I call the c

Re: deriving from float or int

2006-02-21 Thread bearophileHUGS
Probably this is interesting for you: http://home.tiscali.be/be052320/Unum.html I think its API can be improved, but it can be used. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: deriving from float or int

2006-02-20 Thread Sybren Stuvel
Russ enlightened us with: > Does it ever make sense to derive a class from a basic type such as > float or int? Suppose, for example, that I want to create a class > for physical scalars with units. That makes sense. > I thought about deriving from float, then adding the units. I played > around

deriving from float or int

2006-02-20 Thread Russ
Does it ever make sense to derive a class from a basic type such as float or int? Suppose, for example, that I want to create a class for physical scalars with units. I thought about deriving from float, then adding the units. I played around with it a bit, but it doesn't seem to work very well. Am