Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21490
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'attribute': 0.07; 'see:': 0.07; 'skip:` 10': 0.07; 'python': 0.08; 'referencing': 0.09; 'subclass': 0.09; 'am,': 0.12; 'def': 0.13; '"z",': 0.16; '*always*': 0.16; 'a():': 0.16; 'c++.': 0.16; 'doing:': 0.16; 'mro': 0.16; 'new-style': 0.16; 'old-style': 0.16; 'subclassing': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'cheers,': 0.20; 'java': 0.21; 'cc:no real name:2**0': 0.21; 'header:In- Reply-To:1': 0.22; 'sunday,': 0.23; 'wrong?': 0.23; 'received:209.85.220': 0.25; 'cc:2**0': 0.26; 'classes': 0.26; 'function': 0.27; 'message-id:@mail.gmail.com': 0.29; 'explicitly': 0.29; 'class': 0.29; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'object.': 0.30; 'sun,': 0.30; '(the': 0.30; 'chris': 0.30; '(e.g.': 0.31; 'creates': 0.31; 'instead.': 0.32; 'minor': 0.32; 'thanks': 0.32; "isn't": 0.33; 'named': 0.33; 'skip:# 10': 0.34; 'rather': 0.34; 'function.': 0.34; 'latter': 0.34; 'thank': 0.35; 'problem.': 0.35; '...': 0.35; 'things': 0.35; 'url:python': 0.35; 'two': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'skip:_ 10': 0.38; 'received:209.85': 0.38; 'doing': 0.38; 'should': 0.38; 'url:org': 0.39; 'received:209': 0.39; 'point': 0.40; 'your': 0.61; 'march': 0.61; 'cause': 0.67; '11,': 0.68; 'sender:addr:chris': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=w4jfgdffW+XGk/wbVgszO6vjwE2ySNgBtEPEhsYkyUs=; b=c7swxhF2UaDmvCnzH0kzPlXB3ZKEFoyHOll02JSSv6qGu8R0riX2NOFkARxkuFbiJF RGNAmScfzOEMpAv2lOD5GBl6avHM1aXPHs7Zz2xZS4sKRhrluKHHIEx9Do2eJfpb/glM reKCKETLoOyRjIHVtvg54jgShNroM/r999hys= |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=w4jfgdffW+XGk/wbVgszO6vjwE2ySNgBtEPEhsYkyUs=; b=iD4PY9SvXXXRLwHAH1Il6HGa5OfYMUUyqDo0PA7zaGiDAEKnoJh5/N7k96GHbft18I DQrusCxo1jE7AgVOykuw3goOPwRn3OlUQ/n8HfgQZ2ht2NOxcyjEaebGoeBVKi4uKi1D 8aI1U7yzvJlZX6UEke9cfIBIGhe+EYUaXOV+ifOxjbjGiFQ+7vHoN3dV48arjJcPeb51 cNh1Cc/amU/2CbdadE7F7ffSHgU/LkRcg6uUDJSFgD88zb96uw4iUZySRbHa+O6o15O8 aSiJ/XwJJc8od591UA60wg8L49VNZMXhnAs+XtoXijICp/L5p1wBJbsYmuN+2054TLiv yoJg== |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> |
| References | <1c6db866-6fa3-4de5-96de-51d6720a1300@x17g2000yqj.googlegroups.com> <jjg4p3$lst$1@theodyn.ncf.ca> <jjglmi$dao$1@theodyn.ncf.ca> <2feb13ca-f83b-4843-995f-ee77e7505ecd@db5g2000vbb.googlegroups.com> <mailman.560.1331462311.3037.python-list@python.org> <18769501.3541.1331463388634.JavaMail.geo-discussion-forums@ynkz21> |
| Date | Sun, 11 Mar 2012 04:37:55 -0700 |
| X-Google-Sender-Auth | 9XpVYnoUnovseYWPZpjKgmdcFKM |
| Subject | Re: newb __init__ inheritance |
| From | Chris Rebert <clp2@rebertia.com> |
| To | hyperboogie <hyperboogie@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Gm-Message-State | ALoCoQl3i9va58T1IVViW288mpsJvTMvjmQxgsUms10LUjxh4Qiq7hMTUSIZhOgc7Hw5kN2WoflA |
| Cc | python-list@python.org |
| 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.562.1331465879.3037.python-list@python.org> (permalink) |
| Lines | 50 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1331465879 news.xs4all.nl 6943 [2001:888:2000:d::a6]:40968 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:21490 |
Show key headers only | View raw
On Sun, Mar 11, 2012 at 3:56 AM, hyperboogie <hyperboogie@gmail.com> wrote:
> On Sunday, March 11, 2012 12:38:27 PM UTC+2, Chris Rebert wrote:
>> On Sun, Mar 11, 2012 at 3:18 AM, hyperboogie wrote:
>> <snip>
>> > thank you everyone...
>> > Still things are not working as expected... what am I doing wrong?
>> <snip>
>> > # cat test.py
>> > #!/usr/bin/python
>> >
>> > class A():
>>
>> You should be subclassing `object`, but that's a minor point which
>> isn't the cause of your problem.
>>
>> > def __init__(self):
>> > z=1
>>
>> This creates a *local variable* named "z". You want an *attribute*
>> named "z", so you should be doing:
>> self.z = 1
>> instead. Same problem elsewhere; you must *always* explicitly use
>> `self` when referencing an attribute of the current object. Python !=
>> Java or C++.
>>
>> Cheers,
>> Chris
>
> Thanks ... works great now.
> Two last questions:
>
> 1. What do you mean by "subclassing `object`"?
Your classes should (ultimately) subclass the built-in class named
"object". In your case:
class A(object):
# …rest same as before…
This ensures that your classes are new-style rather than old-style
(the latter is deprecated); see:
http://docs.python.org/glossary.html#term-new-style-class
> 2. Is the mro function available only on python3?
There's never been an mro function. Perhaps you mean the __mro__
attribute of classes (e.g. `B.__mro__`), which is available in Python
2.2+ and Python 3?
Cheers,
Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
newb __init__ inheritance hyperboogie <hyperboogie@gmail.com> - 2012-03-08 07:25 -0800
Re: newb __init__ inheritance Maarten <maarten.sneep@knmi.nl> - 2012-03-08 08:30 -0800
Re: newb __init__ inheritance Peter Otten <__peter__@web.de> - 2012-03-08 18:03 +0100
Re: newb __init__ inheritance Ethan Furman <ethan@stoneleaf.us> - 2012-03-08 09:34 -0800
Re: newb __init__ inheritance "Colin J. Williams" <cjw@ncf.ca> - 2012-03-10 12:58 -0500
Re: newb __init__ inheritance "Colin J. Williams" <cjw@ncf.ca> - 2012-03-10 17:47 -0500
Re: newb __init__ inheritance hyperboogie <hyperboogie@gmail.com> - 2012-03-11 03:18 -0700
Re: newb __init__ inheritance Chris Rebert <clp2@rebertia.com> - 2012-03-11 03:38 -0700
Re: newb __init__ inheritance hyperboogie <hyperboogie@gmail.com> - 2012-03-11 03:56 -0700
Re: newb __init__ inheritance Chris Rebert <clp2@rebertia.com> - 2012-03-11 04:37 -0700
Re: newb __init__ inheritance Ian Kelly <ian.g.kelly@gmail.com> - 2012-03-11 05:40 -0600
Re: newb __init__ inheritance Ian Kelly <ian.g.kelly@gmail.com> - 2012-03-11 05:52 -0600
Re: newb __init__ inheritance Peter Otten <__peter__@web.de> - 2012-03-11 13:12 +0100
Re: newb __init__ inheritance hyperboogie <hyperboogie@gmail.com> - 2012-03-11 03:56 -0700
Re: newb __init__ inheritance hyperboogie <hyperboogie@gmail.com> - 2012-03-12 02:09 -0700
csiph-web