subclassing float (or not)

Sean 'Shaleh' Perry shalehperry at attbi.com
Fri Feb 22 15:30:18 EST 2002


On 22-Feb-2002 Thomas Heller wrote:
> I'm currently porting my own rewrite of Konrad Hinsen's PhysicalValue
> module to Python 2.2.
> Basically a PhysicalValue instance is a float conbined with a unit.
> Should I subclass float or should I not? What would I gain by doing
> this (except maybe some memory savings when I use __slots__)?
> 

Generally when you subclass you are saying "I am a special type of foo" where
foo is your parent.  I think in this instance it would make more sense to make
a new class which contains a float and a unit.  Give it methods so it acts how
you expect.




More information about the Python-list mailing list