__init__ return value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Batista, Facundo

    __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__(a sfloat, 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__(a sfloat, p)
    return newobject

    Thanks for all.


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



  • John Roth

    #2
    Re: __init__ return value

    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" <FBatista@uniFO N.com.ar> wrote in message
    news:mailman.10 64424817.693.py thon-list@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__(a sfloat, 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
    fbatista@unifon .com.ar
    (54 11) 5130-4643
    Cel: 15 5132 0132




    Comment

    Working...