Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35835 > unrolled thread
| Started by | contro opinion <contropinion@gmail.com> |
|---|---|
| First post | 2012-12-31 14:34 +0800 |
| Last post | 2013-01-01 11:31 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
the class problem contro opinion <contropinion@gmail.com> - 2012-12-31 14:34 +0800
Re: the class problem Tim Roberts <timr@probo.com> - 2013-01-01 11:31 -0800
| From | contro opinion <contropinion@gmail.com> |
|---|---|
| Date | 2012-12-31 14:34 +0800 |
| Subject | the class problem |
| Message-ID | <mailman.1486.1356935666.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 | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2013-01-01 11:31 -0800 |
| Message-ID | <g8e6e81nf7oo4qrc4pbkdlhbkiljl34mb1@4ax.com> |
| In reply to | #35835 |
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? It doesn't -- that's the right output. What did you expect it to do? The line "class haha(object)" says that "haha" is a class that happens to derive from the "object" base class. The class is still simply called "haha", and to create an instance of the class "haha", you write "haha()". -- Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web