Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35831 > unrolled thread
| Started by | contro opinion <contropinion@gmail.com> |
|---|---|
| First post | 2012-12-31 12:18 +0800 |
| Last post | 2013-01-01 00:37 -0800 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
father class name contro opinion <contropinion@gmail.com> - 2012-12-31 12:18 +0800
Re: father class name Roy Smith <roy@panix.com> - 2012-12-30 23:27 -0500
Re: father class name 88888 Dihedral <dihedral88888@googlemail.com> - 2013-01-01 00:37 -0800
Re: father class name 88888 Dihedral <dihedral88888@googlemail.com> - 2013-01-01 00:37 -0800
| From | contro opinion <contropinion@gmail.com> |
|---|---|
| Date | 2012-12-31 12:18 +0800 |
| Subject | father class name |
| Message-ID | <mailman.1483.1356927535.29569.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
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?
[toc] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2012-12-30 23:27 -0500 |
| Message-ID | <roy-9F211B.23270030122012@news.panix.com> |
| In reply to | #35831 |
In article <mailman.1483.1356927535.29569.python-list@python.org>, contro opinion <contropinion@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.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2013-01-01 00:37 -0800 |
| Message-ID | <96b4f50f-c544-4ca5-98e2-49eba723ca38@googlegroups.com> |
| In reply to | #35831 |
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.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2013-01-01 00:37 -0800 |
| Message-ID | <mailman.1514.1357045223.29569.python-list@python.org> |
| In reply to | #35831 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web