Shidai Liu wrote:
Hi all,

I'll sum up a question as following:

def int5():
    '''return 5'''
    return 5

class my_int(int):
    def __init__(self):
        self.id = int5()
        int.__init__(self, self.id)  # FIXME: this line doesn't work

the above code act like this:

I = my_int()
I

0

I want it to be like this:

I = my_int()
I

5

Please, if you know a solution, help me out!

When you subclass an immutable type like int (or float, string, ...) you have to define __new__ instead of __init__. See this page for an example and some explanation:
http://www.python.org/2.2.3/descrintro.html#__new__


Kent



_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to