|
K Viltersten |
at Mar 4, 2008 at 8:05 pm
|
⇧ |
| |
"Diez B. Roggisch" <deets at nospam.web.de> skrev i meddelandet
news:63346uF25gigqU1 at mid.uni-berlin.de...
K Viltersten schrieb:
I'm writing a class for rational numbers
and besides the most obvious constructor
def __init__ (self, nomin, denom):
i also wish to have two supporting ones
def __init__ (self, integ):
self.__init__ (integ, 1)
def __init__ (self):
self.__init__ (0, 1)
but for some reason (not known to me at
this point) i get errors. My suspicion is that it's a syntax issue.
"errors" is not much of an error-description. That's what stacktraces are
for.
I assumed that the error was so obvious to a
seasoned Pytonist (Pythoner?) that a trace
didn't matter. Your help below proves it. :)
Nevertheless, i'll be careful in the future
and make sure to post the traces too. Sorry.
Apart from that, you won't succeed with the above. Python has no
signature-based polymorphism. Instead, you use default arguments, like
this:
def __init__(nomin=0, denom=1):
...
Thank you.
--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy