Re: father class name
On Monday, December 31, 2012 12:18:48 PM UTC+8, contro opinion wrote: here is my haha class class haha(object): def theprint(self): print i am here The definition of a class named haha. haha().theprint() i am here haha(object).theprint() Traceback (most recent call last): File stdin, line 1, in module TypeError: object.__new__() takes no parameters why haha(object).theprint() get wrong output? You don't have to type the base class object. -- http://mail.python.org/mailman/listinfo/python-list
Re: father class name
Chris Rebert c...@rebertia.com writes: By contrast, in the first part of the *expression* `haha(object).theprint()`, you passed an argument (namely, `object`). Since __init__() wasn't expecting any arguments whatsoever, you therefore got an error. Why is everyone talking about the initialiser, ‘__init__’? When: haha(object).theprint() Traceback (most recent call last): File stdin, line 1, in module TypeError: object.__new__() takes no parameters The error is talking about the constructor, ‘__new__’. -- \ “It's dangerous to be right when the government is wrong.” | `\ —Francois Marie Arouet Voltaire | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: father class name
On Mon, Dec 31, 2012 at 1:23 AM, Ben Finney ben+pyt...@benfinney.id.au wrote: Chris Rebert c...@rebertia.com writes: By contrast, in the first part of the *expression* `haha(object).theprint()`, you passed an argument (namely, `object`). Since __init__() wasn't expecting any arguments whatsoever, you therefore got an error. Why is everyone talking about the initialiser, ‘__init__’? When: haha(object).theprint() Traceback (most recent call last): File stdin, line 1, in module TypeError: object.__new__() takes no parameters The error is talking about the constructor, ‘__new__’. Because the difference between the two (and indeed, the very purpose of the latter) is a topic of intermediate/advanced difficulty, and the OP appears to be a newbie. As I stated, but your quotation omitted: Note: I'm oversimplifying things a bit for the sake of understandability. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: father class name
On Mon, 31 Dec 2012 20:23:44 +1100, Ben Finney wrote: Chris Rebert c...@rebertia.com writes: By contrast, in the first part of the *expression* `haha(object).theprint()`, you passed an argument (namely, `object`). Since __init__() wasn't expecting any arguments whatsoever, you therefore got an error. Why is everyone talking about the initialiser, ‘__init__’? When: haha(object).theprint() Traceback (most recent call last): File stdin, line 1, in module TypeError: object.__new__() takes no parameters The error is talking about the constructor, ‘__new__’. Good point. I think we do a disservice to newbies when we (inadvertently) discourage them from reading the tracebacks generated by an error. The traceback clearly talks about a __new__ method. I don't believe that talking about the constructor __new__ is so complicated that we should ignore the actual error and go of on a wild- goose chase about the initialiser __init__, especially since adding an __init__ method to the class *won't solve the problem*. Sorry Chris, I think you dropped the ball on this one and gave an overtly misleading answer :-( -- Steven -- http://mail.python.org/mailman/listinfo/python-list
father class name
here is my haha class class haha(object): def theprint(self): print i am here haha().theprint() i am here haha(object).theprint() Traceback (most recent call last): File stdin, line 1, in module TypeError: object.__new__() takes no parameters why haha(object).theprint() get wrong output? -- http://mail.python.org/mailman/listinfo/python-list
Re: father class name
In article mailman.1483.1356927535.29569.python-l...@python.org, contro opinion contropin...@gmail.com wrote: here is my haha class class haha(object): def theprint(self): print i am here haha().theprint() i am here haha(object).theprint() Traceback (most recent call last): File stdin, line 1, in module TypeError: object.__new__() takes no parameters why haha(object).theprint() get wrong output? Please, when asking questions, let us know what version of python you're using. I'm guessing 2.x? In any case, the problem is that you defined a class whose constructor takes no arguments: class haha(object): def theprint(self): print i am here You didn't define an __init__() method, so it inherits the one from the base class, object. Then here: haha(object).theprint() you try to create an instance of your class and give an argument to the constructor. -- http://mail.python.org/mailman/listinfo/python-list
Re: father class name
On 2012.12.30 22:18, contro opinion wrote: here is my haha class class haha(object): def theprint(self): print i am here haha().theprint() i am here haha(object).theprint() Traceback (most recent call last): File stdin, line 1, in module TypeError: object.__new__() takes no parameters why haha(object).theprint() get wrong output? You have no __init__() method defined that would take parameters. What are you trying to do? -- CPython 3.3.0 | Windows NT 6.2.9200.16461 -- http://mail.python.org/mailman/listinfo/python-list
Re: father class name
On Sun, Dec 30, 2012 at 8:18 PM, contro opinion contropin...@gmail.com wrote: here is my haha class class haha(object): def theprint(self): print i am here haha().theprint() i am here haha(object).theprint() Traceback (most recent call last): File stdin, line 1, in module TypeError: object.__new__() takes no parameters why haha(object).theprint() get wrong output? The fact that `haha(object)` is textually part of the *declaration* `class haha(object):` has no bearing on how one instantiates an instance of the class `haha`. In the `class` statement, `haha` is being declared to be a subclass of class `object` (that's what it means for `object` to be in the parentheses after the class name in a `class` statement; the syntax is class classname(base classes):). In the first part of the *expression* `haha().theprint()`, you are using the function-call operator on the `haha` class itself, which has the effect of instantiating it; since you gave no arguments in the function call, haha's initializer (i.e. its __init__() method) was given no arguments. Since you didn't define an __init__() method for haha, haha inherited the default __init__() method from class `object`, which takes no arguments, so your call was fine and worked as expected. By contrast, in the first part of the *expression* `haha(object).theprint()`, you passed an argument (namely, `object`). Since __init__() wasn't expecting any arguments whatsoever, you therefore got an error. The parentheses in a `class` statement do NOT signify a function call; they are part of the syntax of the `class` statement itself. Cheers, Chris -- Note: I'm oversimplifying things a bit for the sake of understandability. -- http://mail.python.org/mailman/listinfo/python-list