inherit from data type

R

Richard Lamboj

Hello,

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?

Kind Regards

Richi
 
U

Ulrich Eckhardt

Richard said:
i want to inherit from a data type. How can i do this? Can anyone explain
more abou this?

Other than in e.g. C++ where int and float are special types, you can
inherit from them in Python like from any other type. The only speciality
of int, float and string is that they are immutable.
How knows python that it is a float, or a string?

I'm not actually sure I understand this question. If you derive from float,
Python obviously knows that you derive from float....


Uli
 
B

Bruno Desthuilliers

R

Richard Lamboj

Am Tuesday 11 May 2010 10:47:35 schrieb Ulrich Eckhardt:
Other than in e.g. C++ where int and float are special types, you can
inherit from them in Python like from any other type. The only speciality
of int, float and string is that they are immutable.


I'm not actually sure I understand this question. If you derive from float,
Python obviously knows that you derive from float....


Uli

"How knows python that it is a float, or a string?" Sorry this was bad
expressed. I want to create a new data type, which inherits from float. I
just know the "dir" function and the "help" function to get more infromations
about the class, but i need to get more information about the class
structure.

What i also want to know:<type 'float'>

Is there a way to tell python that it use antoher class than float for float,
like myfloat? Its just a "tell-me-what-is-possible".

Sample:<type 'myfloat'>

Kind Regards,

Richi
 
C

Chris Rebert

On Tue, May 11, 2010 at 2:18 AM, Richard Lamboj
What i also want to know:
<type 'float'>

Is there a way to tell python that it use antoher class than float for float,
like myfloat? Its just a "tell-me-what-is-possible".

Sample:
<type 'myfloat'>

No, it's not possible to have the float literal syntax produce
instances of your custom subclass.

Cheers,
Chris
 
U

Ulrich Eckhardt

Richard said:
"How knows python that it is a float, or a string?" Sorry this was bad
expressed. I want to create a new data type, which inherits from float. I
just know the "dir" function and the "help" function to get more
infromations about the class, but i need to get more information about the
class structure.

I'd suggest the tutorial, see http://docs.python.org, though your question
is already beyond the range of beginners' questions.
What i also want to know:
<type 'float'>

Is there a way to tell python that it use antoher class than float for
float, like myfloat? Its just a "tell-me-what-is-possible".

Sample:
<type 'myfloat'>

The expression "10.5" will always be a float, you can't change that. What
you can do is create your own type, derived from float:
... pass
...

and then create an object of that type:


Lastly one warning: In many cases where people wanted to derive from a
concrete data type, their problems were easier solved by external code. I
don't know your problem though.

Uli
 
R

Richard Lamboj

Am Tuesday 11 May 2010 11:38:42 schrieb Ulrich Eckhardt:
I'd suggest the tutorial, see http://docs.python.org, though your question
is already beyond the range of beginners' questions.


The expression "10.5" will always be a float, you can't change that. What

you can do is create your own type, derived from float:

... pass
...

and then create an object of that type:

<class '__main__.myfloat'>



Lastly one warning: In many cases where people wanted to derive from a
concrete data type, their problems were easier solved by external code. I
don't know your problem though.

Uli

I just want to test what is possible with python and what not. There is no
problem that i need to solve.

This is what i'am searching for:
http://docs.python.org/reference/datamodel.html

Last year i have stopped programming python, but now i'am back with a big
black hole in my brain and i want to understand what the interpreter is doing
in the background.

I think my question was not well formulated...

Kind Regards
 
T

Terry Reedy

I just want to test what is possible with python and what not. There is no
problem that i need to solve.

This is what i'am searching for:
http://docs.python.org/reference/datamodel.html

Last year i have stopped programming python, but now i'am back with a big
black hole in my brain and i want to understand what the interpreter is doing
in the background.

I suggest you (re)read and try examples in the Tutorial. It covers the
basic syntax pretty well.
 
R

Richard Lamboj

Am Tuesday 11 May 2010 20:16:50 schrieb Terry Reedy:
I suggest you (re)read and try examples in the Tutorial. It covers the
basic syntax pretty well.

There are many programming languages, so i have forgotten that python data
types are objects and not a "wrapper". So its a little bit confusing
that "self" returns the value of the datatype and not something
like "self.value". But who cares about logical mistakes in my brain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,103
Latest member
VinaykumarnNevatia
Top