Dear Everyone,
I have tried reading all the tutorials and documentation about class
inheritance and I was trying to do simple experiments with sage.
Suppose I want to introduce a new class of integers that would behave
identically to the integers but have the _repr_ function changed a bit:
I don't know, maybe I want the results to be printed in base 5 or something
similar.
Following the tutorial I should first start by defining the new elements.
In the tutorial the elements inherit from the generic "FieldElement". I
would like to inherit from "Integer"
sage: class NewIntEl(Integer):
def __init__(self, parent, x=None):
Integer.__init__(self, x)
def _repr_(self):
return "NewInt representation funtion says: %s"%Integer.
_repr_(self)
....:
but unfortunately nothing works:
sage: NewIntEl(ZZ,1)
0
And nothing changes if I change the init line to:
def __init__(self, parent, x=None):
Integer.__init__(self, parent, x)
even though the constructor of Integer doesn't seem to require the "parent".
Obviously continuing to write down the definition for the new class of
NewInt doens't make sense because this part doesn't work. I cannot find any
clue as what is wrong. From other experiments it seems that the __init__
doesn't get executed AT ALL.
Please help.
Sincerely,
Gennady Uraltsev.
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.