Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12552
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <motoom@xs4all.nl> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; '"if': 0.04; 'constructor': 0.07; 'underscores': 0.09; 'def': 0.15; 'class,': 0.15; 'from:addr:xs4all.nl': 0.16; 'message-id:@xs4all.nl': 0.16; 'received:194.109': 0.16; 'received:194.109.24': 0.16; 'received:xs4all.nl': 0.16; 'subject:PROBLEM': 0.16; 'x-mailer:apple mail (2.1084)': 0.16; 'wrote:': 0.16; 'say,': 0.19; 'badly': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'sep': 0.23; 'object,': 0.24; 'hey': 0.26; 'function': 0.27; 'problem': 0.28; 'print': 0.29; 'class': 0.30; 'does': 0.32; 'it.': 0.33; 'to:addr:python-list': 0.33; 'object': 0.35; 'charset :us-ascii': 0.36; 'but': 0.37; 'something': 0.37; 'two': 0.37; 'think': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'chosen': 0.40; 'your': 0.61; 'header:Message-Id:1': 0.61; 'greetings,': 0.66; 'subject:!': 0.67; 'derive': 0.84; 'distinguish': 0.84; 'things:': 0.91 |
| Content-Type | text/plain; charset=us-ascii |
| Mime-Version | 1.0 (Apple Message framework v1084) |
| Subject | Re: Constructors...BIIIIG PROBLEM! |
| From | Michiel Overtoom <motoom@xs4all.nl> |
| In-Reply-To | <CABWGKeW6sw2GJghQRbPcUA7_EO2V7SX5iJH0Pz0u513wX9TPNw@mail.gmail.com> |
| Date | Thu, 1 Sep 2011 10:00:27 +0200 |
| Content-Transfer-Encoding | quoted-printable |
| References | <CABWGKeW6sw2GJghQRbPcUA7_EO2V7SX5iJH0Pz0u513wX9TPNw@mail.gmail.com> |
| To | PYTHON <python-list@python.org> |
| X-Mailer | Apple Mail (2.1084) |
| X-Virus-Scanned | by XS4ALL Virus Scanner |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.650.1314864664.27778.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1314864664 news.xs4all.nl 2402 [2001:888:2000:d::a6]:55348 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:12552 |
Show key headers only | View raw
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Constructors...BIIIIG PROBLEM! Michiel Overtoom <motoom@xs4all.nl> - 2011-09-01 10:00 +0200
csiph-web