469,328 Members | 1,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

__init__ return value

Studying the Tim Peter's FixedPoint code, found this:

# can we coerce to a float?
yes = 1
try:
asfloat = float(value)
except:
yes = 0
if yes:
self.__init__(asfloat, p)
return

This code is part of the __init__ method of the class.

The question is about the last two lines: When you call self.__init__(...),
doesn't it return a value that you should return too?

I thought it could be like this:

....
if yes:
newobject = self.__init__(asfloat, p)
return newobject

Thanks for all.
Facundo Batista
Gestión de Red
fb******@unifon.com.ar
(54 11) 5130-4643
Cel: 15 5132 0132

Jul 18 '05 #1
1 3745
No. __init__(self) returns None. In fact, I'm not certain whether
it even checks for the value of the return. __init__()'s function is
to initialize the instance which is it's first parameter, you cannot
change the instance it is working on.

If you need to provide your own instance object, use __new__().

John Roth
"Batista, Facundo" <FB******@uniFON.com.ar> wrote in message
news:ma********************************@python.org ...
Studying the Tim Peter's FixedPoint code, found this:

# can we coerce to a float?
yes = 1
try:
asfloat = float(value)
except:
yes = 0
if yes:
self.__init__(asfloat, p)
return

This code is part of the __init__ method of the class.

The question is about the last two lines: When you call self.__init__(...),
doesn't it return a value that you should return too?

Thanks for all.
Facundo Batista
Gestión de Red
fb******@unifon.com.ar
(54 11) 5130-4643
Cel: 15 5132 0132


Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Felix Wiemann | last post: by
14 posts views Thread by Axel Straschil | last post: by
5 posts views Thread by NavyJay | last post: by
8 posts views Thread by kelin,zzf818 | last post: by
19 posts views Thread by dickinsm | last post: by
3 posts views Thread by Steven W. Orr | last post: by
4 posts views Thread by Steven D'Aprano | last post: by
25 posts views Thread by Erik Lind | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.