Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem deriving form type long

3 views
Skip to first unread message

Frederic Rentsch

unread,
Jan 21, 2008, 3:33:10 PM1/21/08
to pytho...@python.org
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

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.)

Gabriel Genellina

unread,
Jan 21, 2008, 4:19:14 PM1/21/08
to pytho...@python.org
En Mon, 21 Jan 2008 18:33:10 -0200, Frederic Rentsch
<anthra...@vtxmail.ch> escribi�:

> 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 Rentsch

unread,
Jan 23, 2008, 8:08:01 AM1/23/08
to pytho...@python.org
Gabriel Genellina wrote:
> En Mon, 21 Jan 2008 18:33:10 -0200, Frederic Rentsch
> <anthra...@vtxmail.ch> escribió:

>
>> 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
That's a big help! Thank you very much.

Frederic

0 new messages