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


Groups > comp.lang.python > #48980

Re: What is the semantics meaning of 'object'?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jiang.adam@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'classes,': 0.05; 'class,': 0.07; 'result,': 0.07; 'classes.': 0.09; 'subtle': 0.09; 'python': 0.11; 'django': 0.11; 'def': 0.12; '"a"': 0.16; '"python': 0.16; '(without': 0.16; '23,': 0.16; '>on': 0.16; 'a(object):': 0.16; 'adam': 0.16; 'arg):': 0.16; 'called.': 0.16; 'class:': 0.16; 'inheritance': 0.16; 'interpreter,': 0.16; 'likewise': 0.16; 'merely': 0.16; 'new-style': 0.16; 'notation,': 0.16; 'object;': 0.16; 'old-style': 0.16; 'quotes)': 0.16; 'semantics': 0.16; 'subject:object': 0.16; 'type)': 0.16; 'sat,': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'slightly': 0.19; 'seems': 0.21; 'print': 0.22; 'header:User-Agent:1': 0.23; '(or': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'class.': 0.26; 'defined': 0.27; 'header:In- Reply-To:1': 0.27; "doesn't": 0.30; 'url:mailman': 0.30; 'usually': 0.31; '-0700,': 0.31; "d'aprano": 0.31; 'raised': 0.31; 'steven': 0.31; 'class': 0.32; 'another': 0.32; 'url:python': 0.33; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'classes': 0.35; 'good.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'url:org': 0.36; 'should': 0.36; 'example,': 0.37; 'to:addr:python-list': 0.38; 'previous': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'include:': 0.61; 'interested,': 0.61; 'back': 0.62; 'content-disposition:inline': 0.62; 'name': 0.63; 'kind': 0.63; 'such': 0.63; 'field': 0.63; 'received:122': 0.63; 'refer': 0.63; 'here': 0.66; 'between': 0.67; 'book,': 0.68; 'special': 0.74; "'object'": 0.84; '2.2.': 0.84; 'delegation': 0.84; 'unifying': 0.84; 'differences': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=agK299kAWDYZCfnLdwJbEbgnT6wrJups5fHSHlTVX1c=; b=mfa9nLxsJWnaJf3un9HF/gmFtb2DzcNW7IXxw0mXGwtgAsvk8grySRlglDOfdghCL9 /lyOM+PNeDI78sEphJKMVru6uIxyZ+NbqxC1iOI2Hwr9shX58aArdhxnJyzWoaMj9Ko/ dbsb+IT8Ack45a1Z7grpaviiDZXKWmMEmbGjlcWfg6S6amSPacyuWs4q/f/T0cvQ4MM3 iOqyl/rhlQcb8JKaBB2Ni2Zaaq0gijHkG5UsuZpfWOxA7f63ps3vyYj+5HikKFZB0wcX 8iDM/nSbFMlQUvMr9O5e9BvVtSq2FGwWmudwD/0fFXKV5NAeUBg0lGqh69KspNcTNUBg rHkg==
X-Received by 10.67.4.196 with SMTP id cg4mr24182346pad.117.1371994555950; Sun, 23 Jun 2013 06:35:55 -0700 (PDT)
Date Sun, 23 Jun 2013 22:35:46 +0900
From Adam Jiang <jiang.adam@gmail.com>
To python-list@python.org
Subject Re: What is the semantics meaning of 'object'?
References <15ba0011-bbf1-42f7-b3ea-1c1d4b70e56b@googlegroups.com> <51c66962$0$29999$c3e8da3$5496439d@news.astraweb.com>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
In-Reply-To <51c66962$0$29999$c3e8da3$5496439d@news.astraweb.com>
User-Agent Mutt/1.5.21 (2010-09-15)
Cc Steven D'Aprano <steve+comp.lang.python@pearwood.info>
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.3726.1371994559.3114.python-list@python.org> (permalink)
Lines 82
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371994559 news.xs4all.nl 15928 [2001:888:2000:d::a6]:54586
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48980

Show key headers only | View raw


> * property only works in "new-style" classes that inherit from object;
> 
> * likewise for super;

Another question raised here is that what is the proper way to refer
to parent class? For example,

class A(object):
        def __init__(self, arg):
                print "A"

class B(A):
        def __init__(self, arg):
                super(B, self).__init__(arg)

Is this correct? As the result, whenever you wanted to refer to a
method in parent class, super() functions has to be called. This seems
inefficient.

How to refer to a field defined in parent class?

Thanks,
/Adam

>On Sun, Jun 23, 2013 at 03:20:02AM +0000, Steven D'Aprano wrote:
> On Sat, 22 Jun 2013 19:58:38 -0700, Adam wrote:
> 
> > class FooBar(object):
> >     def __init__(self):
> >         ...
> > 
> > Inheritance usually takes a class name to indicate which class is the
> > 'parent' class. However, in the previous example, from a django book,
> > the class actually takes an 'object' like parameter, doesn't it? What is
> > the semantics meaning of such kind of notation?
> 
> It's not merely notation, "object" is the name of a class. If you type it 
> (without quotes) at the interactive interpreter, you will see it is a 
> built-in class:
> 
> py> object
> <class 'object'>
> 
> 
> In Python 3, the use of object as base class is optional, but in Python 2 
> there is a subtle difference between classes that inherit from object and 
> those that don't. The reason for this difference is buried in the mists 
> of time, going back to Python 2.2. If you are interested, google on 
> "Python unifying types and classes":
> 
> https://duckduckgo.com/html/?q=Python+unifying+types+and+classes
> 
> 
> As a general rule, unless you actually want "old-style class" behaviour, 
> you should always inherit from object (or some other built-in type) in 
> Python 2. In Python 3, it doesn't matter.
> 
> The differences include:
> 
> * property only works in "new-style" classes that inherit from object;
> 
> * likewise for super;
> 
> * multiple inheritance with old-style classes can be buggy;
> 
> * new-style classes may be slightly faster in general;
> 
> * on the down side, automatic delegation of special double-underscore 
> methods like __getitem__ and __str__ doesn't work with new-style classes.
> 
> 
> If none of this means anything to you, be glad, and just inherit from 
> object or some other built-in type in all your classes, and all will be 
> good.
> 
> 
> 
> 
> -- 
> Steven
> -- 
> http://mail.python.org/mailman/listinfo/python-list

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


Thread

What is the semantics meaning of 'object'? Adam <jiang.adam@gmail.com> - 2013-06-22 19:58 -0700
  Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 03:20 +0000
    Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-22 22:27 -0600
      Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 05:23 +0000
        Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-22 23:40 -0600
          Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 17:29 +0000
            Re: What is the semantics meaning of 'object'? Rotwang <sg552@hotmail.co.uk> - 2013-06-24 02:53 +0100
              Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-24 06:31 +0000
                Re: What is the semantics meaning of 'object'? Rotwang <sg552@hotmail.co.uk> - 2013-06-24 16:00 +0100
                Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-24 11:23 -0600
    Re: What is the semantics meaning of 'object'? Adam Jiang <jiang.adam@gmail.com> - 2013-06-23 22:35 +0900
    Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-23 10:15 -0600
      Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 16:35 +0000
        Re: What is the semantics meaning of 'object'? Roy Smith <roy@panix.com> - 2013-06-23 12:49 -0400
          Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-23 11:08 -0600
            Re: What is the semantics meaning of 'object'? Roy Smith <roy@panix.com> - 2013-06-23 14:14 -0400
          Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-23 11:18 -0600
            Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 17:36 +0000
              Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-23 12:04 -0600
                Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 18:50 +0000
                Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-23 13:09 -0600
                Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-24 01:12 +0000
                Re: What is the semantics meaning of 'object'? Roy Smith <roy@panix.com> - 2013-06-23 15:24 -0400
                Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-24 01:27 +0000
                Re: What is the semantics meaning of 'object'? Roy Smith <roy@panix.com> - 2013-06-23 21:38 -0400
                Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-24 08:06 +0000
                Re: What is the semantics meaning of 'object'? Roy Smith <roy@panix.com> - 2013-06-24 08:41 -0400
                Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-24 08:58 -0700
                Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-24 23:51 +0000
                Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-24 11:26 -0600
                Re: What is the semantics meaning of 'object'? Ethan Furman <ethan@stoneleaf.us> - 2013-06-26 13:14 -0700
                Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-26 23:54 +0000
                Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-26 19:03 -0600
                Re: What is the semantics meaning of 'object'? Ethan Furman <ethan@stoneleaf.us> - 2013-06-26 17:38 -0700
          Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 18:46 +0000
            Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-23 13:05 -0600
            Re: What is the semantics meaning of 'object'? Ethan Furman <ethan@stoneleaf.us> - 2013-06-26 13:37 -0700
          Re: What is the semantics meaning of 'object'? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-23 13:33 -0700
        Re: What is the semantics meaning of 'object'? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-06-23 21:33 +0200
        Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-25 11:44 -0600
        Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-25 14:58 -0700
        Re: What is the semantics meaning of 'object'? Chris Angelico <rosuav@gmail.com> - 2013-06-26 08:17 +1000
        Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-25 16:21 -0600
        Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-25 16:25 -0600
        Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-25 15:29 -0700
        Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-25 15:27 -0700
        Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-25 15:38 -0700
        Re: What is the semantics meaning of 'object'? Chris Angelico <rosuav@gmail.com> - 2013-06-26 08:39 +1000
        Re: What is the semantics meaning of 'object'? Chris Angelico <rosuav@gmail.com> - 2013-06-26 08:47 +1000
        Re: What is the semantics meaning of 'object'? Chris Angelico <rosuav@gmail.com> - 2013-06-26 08:57 +1000
          Re: What is the semantics meaning of 'object'? Rotwang <sg552@hotmail.co.uk> - 2013-06-26 16:16 +0100
            Re: What is the semantics meaning of 'object'? Chris Angelico <rosuav@gmail.com> - 2013-06-27 01:23 +1000
        Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-25 17:07 -0600
        Re: What is the semantics meaning of 'object'? Chris Angelico <rosuav@gmail.com> - 2013-06-26 09:08 +1000
        Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-25 17:10 -0600
        Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-25 16:19 -0700
          Re: What is the semantics meaning of 'object'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-26 08:36 +0000
          Re: What is the semantics meaning of 'object'? alex23 <wuwei23@gmail.com> - 2013-06-28 10:19 +1000
            Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-28 11:55 -0700
        Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-25 16:00 -0700
        Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-25 18:19 -0600
        Re: What is the semantics meaning of 'object'? Mark Janssen <dreamingforward@gmail.com> - 2013-06-25 18:07 -0700
        Re: What is the semantics meaning of 'object'? Chris Angelico <rosuav@gmail.com> - 2013-06-26 17:25 +1000
        Re: What is the semantics meaning of 'object'? Ian Kelly <ian.g.kelly@gmail.com> - 2013-06-26 02:53 -0600
        Re: What is the semantics meaning of 'object'? Chris Angelico <rosuav@gmail.com> - 2013-06-26 09:54 +1000
        Re: What is the semantics meaning of 'object'? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-06-26 12:56 +0200
      Re: What is the semantics meaning of 'object'? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-23 13:12 -0700

csiph-web