>>> class Fix_Point (long):
def __init__ (self, l):
long.__init__ (self, l * 0x10000):
>>> fp = Fix_Point (99)
>>> fp
99
With prints:
>>> class Fix_Point (long):
def __init__ (self, l):
print l
l_ = l * 2
print l_
long.__init__ (self, l_)
print self
>>> fp = Fix_Point (99)
99
198
99
I have tried dozens of variations: type casts, variables, ... nothing
doing. Fix_Point instances always get the argument assigned regardless
of the transformation __init__ () performs on it prior to calling
long.__init__ (). Looks like long.__init__ () isn't called at all. Any
idea anyone what's going on?
Frederic
(P.S. I am not currently a subscriber. I was and had to bail out when I
couldn't handle the volume anymore. To subscribe just to post one
question doesn't seem practical at all. So, I don't even know if this
message goes through. In case it does, I would appreciate a CC directly
to my address, as I don't think I can receive the list. Thanks a million.)
> Hi, here's something that puzzles me:
>
> >>> class Fix_Point (long):
> def __init__ (self, l):
> long.__init__ (self, l * 0x10000):
>
> >>> fp = Fix_Point (99)
> >>> fp
> 99
You have to override __new__, not __init__. Immutable types like numbers
and tuples don't use __init__.
See http://docs.python.org/ref/customization.html
> (P.S. I am not currently a subscriber. I was and had to bail out when I
> couldn't handle the volume anymore. To subscribe just to post one
> question doesn't seem practical at all. So, I don't even know if this
> message goes through. In case it does, I would appreciate a CC directly
> to my address, as I don't think I can receive the list. Thanks a
> million.)
You can read this thru the Google Groups interfase:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ade1fdc42c5380b8/
or using Gmane:
http://thread.gmane.org/gmane.comp.python.general/555822
--
Gabriel Genellina
Frederic