__init__ return value

B

Batista, Facundo

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
(e-mail address removed)
(54 11) 5130-4643
Cel: 15 5132 0132
 
J

John Roth

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


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
(e-mail address removed)
(54 11) 5130-4643
Cel: 15 5132 0132
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top