Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12552 > unrolled thread
| Started by | Michiel Overtoom <motoom@xs4all.nl> |
|---|---|
| First post | 2011-09-01 10:00 +0200 |
| Last post | 2011-09-01 10:00 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Constructors...BIIIIG PROBLEM! Michiel Overtoom <motoom@xs4all.nl> - 2011-09-01 10:00 +0200
| From | Michiel Overtoom <motoom@xs4all.nl> |
|---|---|
| Date | 2011-09-01 10:00 +0200 |
| Subject | Re: Constructors...BIIIIG PROBLEM! |
| Message-ID | <mailman.650.1314864664.27778.python-list@python.org> |
On Sep 1, 2011, at 09:48, Amogh M S wrote:
> Hey guys...
> I think we have a problem with my _init_ method and the constructor
> When I create a class and its _init_ method and try to create an object of it outside the class,
> Say, something like
>
> class S:
> def _init_(self, name=None):
> self.name = name
> s = S("MyName")
Two things: Derive your class from object, and the constructor function should be '__init__', that is, with *two* underscores before and after it. Are you reading a book or tutorial which does use a badly chosen font which doesn't distinguish two consecutive underscores well?
class S(object):
def __init__(self, name=None):
self.name = name
s = S("MyName")
print s.name
Greetings,
--
"If you don't know, the thing to do is not to get scared, but to learn." - Ayn Rand
Back to top | Article view | comp.lang.python
csiph-web