inherit from data type

James Mills prologic at shortcircuit.net.au
Tue May 11 04:58:00 EDT 2010


On Tue, May 11, 2010 at 6:38 PM, Richard Lamboj
<richard.lamboj at bilcom.at> wrote:
> i want to inherit from a data type. How can i do this? Can anyone explain more
> abou this? How knows python that it is a float, or a string?

$ python
Python 2.6.5 (r265:79063, Apr 27 2010, 18:26:49)
[GCC 4.4.1 (CRUX)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class MyFloat(float):
...     def __repr__(self):
...             return "MyFloat(%f)" % self
...
>>> x = MyFloat(3.1415926535897931)
>>> x
MyFloat(3.141593)
>>>

--James



More information about the Python-list mailing list