473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

__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 3873
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: user | last post by:
I have gotten properties to respond correctly, but when I try to do it in __init__: class foo: def getter(self): return "hello" def __init__(self):
9
by: Felix Wiemann | last post by:
Sometimes (but not always) the __new__ method of one of my classes returns an *existing* instance of the class. However, when it does that, the __init__ method of the existing instance is called...
14
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
5
by: NavyJay | last post by:
I have a simple for-loop, which instantiates a class object each iteration. As part of my class constructor, __init__(), I check for valid input settings. If there is a problem with this...
8
by: kelin,zzf818 | last post by:
Hi, Today I read the following sentences, but I can not understand what does the __init__ method of a class do? __init__ is called immediately after an instance of the class is created. It...
19
by: dickinsm | last post by:
Here's an example of a problem that I've recently come up against for the umpteenth time. It's not difficult to solve, but my previous solutions have never seemed quite right, so I'm writing to...
3
by: Steven W. Orr | last post by:
When I go to create an object I want to be able to decide whether the object is valid or not in __init__, and if not, I want the constructor to return something other than an object, (like maybe...
4
by: Steven D'Aprano | last post by:
When you call a new-style class, the __new__ method is called with the user-supplied arguments, followed by the __init__ method with the same arguments. I would like to modify the arguments...
25
by: Erik Lind | last post by:
I'm new to Python, and OOP. I've read most of Mark Lutz's book and more online and can write simple modules, but I still don't get when __init__ needs to be used as opposed to creating a class...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.