Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35841

Re: father class name

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'received:209.85.223': 0.03; 'syntax': 0.03; 'argument': 0.04; 'skip:` 10': 0.05; 'arguments': 0.07; 'arguments,': 0.09; 'expected.': 0.09; 'inherited': 0.09; 'it;': 0.09; 'itself,': 0.09; 'sake': 0.09; 'subclass': 0.09; 'typeerror:': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; 'itself.': 0.11; 'dec': 0.15; '*expression*': 0.16; 'here"': 0.16; 'instantiates': 0.16; 'output?': 0.16; 'parentheses': 0.16; 'statement;': 0.16; 'subject:class': 0.16; 'textually': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'skip:` 20': 0.17; 'define': 0.20; 'parameters': 0.20; 'bit': 0.21; 'error.': 0.21; '"",': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'statement': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(most': 0.27; 'message- id:@mail.gmail.com': 0.27; 'chris': 0.28; 'fine': 0.28; '>>>>': 0.29; 'arguments.': 0.29; 'contrast,': 0.29; 'declared': 0.29; 'class': 0.29; "i'm": 0.29; 'worked': 0.30; 'function': 0.30; 'file': 0.32; 'print': 0.32; 'traceback': 0.33; 'received:google.com': 0.34; 'wrong': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; '(i.e.': 0.36; "wasn't": 0.36; "didn't": 0.36; 'method': 0.36; 'being': 0.37; 'why': 0.37; 'passed': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'things': 0.38; 'takes': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'first': 0.61; '30,': 0.62; 'note:': 0.64; 'here': 0.65; 'gave': 0.65; 'therefore': 0.65; '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; bh=hlo2I9x1lfIXXMBIJnlH9HoQOOGX7yLiyQ3fny31z5s=; b=MN7tVBVPKQvC0T6gatkEPFSP8QvgbOEeBwFenP5jqzEq9pzVRbrWqc6kaTDg5H3VOS L1EZkoGz1iJklqSKYyMHNAICuXlZYPszln0/euueRladjo+tvU4vIBc9BrisH2hs1QmZ LVCJjlapb+tnGw/JrqDt6u9Ywx/l7MbHHXqC0=
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 :x-gm-message-state; bh=hlo2I9x1lfIXXMBIJnlH9HoQOOGX7yLiyQ3fny31z5s=; b=Tz0SbMYkbF3BBFvaXS2Vpilo+G027KHzFGIOZKRn4E8XZA7NrVEA73duRd+Tm22tqV CdOltNsaW/lvayDAa1HcTDbfs2Cj50BhPvPp9lwDgpB3B2EwmYVC6oDmAIjl2fe1tfgw dqE0G30QJHnXLbn9mOCGsQIOlLTuEW1DtiscriQQTut9E/wFE+JqvZiVoHXjHYC6NqGM UtzR0kJ9zOlyWYUwkmi35d+MmbiZs3qsF4MQJxCSLghmhXeK6xlqguRxJaxD1f3TeMOu hVkBYmR9t4+pXUT1SSOb3sXA2hgTcBIeI72hH0A4Xo5+flJ66QzkuThFUyllm2SeshPX af4A==
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <CA+YdQ_6v3m5JH0PusuYffb9xa=U56sNGKxYmy_w0hU04V8ZvgQ@mail.gmail.com>
References <CA+YdQ_6v3m5JH0PusuYffb9xa=U56sNGKxYmy_w0hU04V8ZvgQ@mail.gmail.com>
Date Sun, 30 Dec 2012 23:27:39 -0800
X-Google-Sender-Auth nxNFix4YxrSN5MEcY6A12QYpwxw
Subject Re: father class name
From Chris Rebert <clp2@rebertia.com>
To contro opinion <contropinion@gmail.com>
Content-Type text/plain; charset=UTF-8
X-Gm-Message-State ALoCoQnyPaGNqMHhq8KiWtHZVLoNEF7xNHevEz+zzQ4JKjUdiT6oZeSFx2evv6zrIq78NOH0/DJ1
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.1492.1356938863.29569.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1356938863 news.xs4all.nl 6875 [2001:888:2000:d::a6]:50699
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35841

Show key headers only | View raw


On Sun, Dec 30, 2012 at 8:18 PM, 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?

The fact that `haha(object)` is textually part of the *declaration*
`class haha(object):` has no bearing on how one instantiates an
instance of the class `haha`.
In the `class` statement, `haha` is being declared to be a subclass of
class `object` (that's what it means for `object` to be in the
parentheses after the class name in a `class` statement; the syntax is
"class <classname>(<base classes>):").

In the first part of the *expression* `haha().theprint()`, you are
using the function-call operator on the `haha` class itself, which has
the effect of instantiating it; since you gave no arguments in the
function call, haha's initializer (i.e. its __init__() method) was
given no arguments. Since you didn't define an __init__() method for
haha, haha inherited the default __init__() method from class
`object`, which takes no arguments, so your call was fine and worked
as expected.

By contrast, in the first part of the *expression*
`haha(object).theprint()`, you passed an argument (namely, `object`).
Since __init__() wasn't expecting any arguments whatsoever, you
therefore got an error.

The parentheses in a `class` statement do NOT signify a function call;
they are part of the syntax of the `class` statement itself.

Cheers,
Chris
--
Note: I'm oversimplifying things a bit for the sake of understandability.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: father class name Chris Rebert <clp2@rebertia.com> - 2012-12-30 23:27 -0800

csiph-web