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


Groups > comp.lang.python > #63310

Re: class inheritance python2.7 vs python3.3

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.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; 'explicitly': 0.05; '"""': 0.07; 'class,': 0.07; 'versions.': 0.07; '__init__': 0.09; 'default.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '__new__': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'old-style': 0.16; 'redundant': 0.16; 'subclass': 0.16; 'subclassing': 0.16; 'subject:class': 0.16; 'subject:python2.7': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'appears': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'important.': 0.30; 'message-id:@mail.gmail.com': 0.30; 'class': 0.32; 'there.': 0.32; 'probably': 0.32; 'skip:_ 10': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'two': 0.37; 'though,': 0.39; 'simply': 0.61; "you're": 0.61; 'different': 0.65; 'object:': 0.84; 'subtly': 0.84; 'thing,': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=pZyeDHvFALzs9JGleGY5icLpLsRlQw7Y5qtWzYnPoSs=; b=XzyynRmiAxXVL4RuDeH7Rcn547b5lsV3aFZPxIV0D4v6l9QYlQZs+BEsiMwjx+qd2s dmbb6t2NPOfJIbV4YHuqU+4YHRPmmRkVPlqeuuiYjqS58i2li3QA/4NAMuyc8r1jAhN6 f6T+yVj1K4W5S6nQ6UsXvY3amtkDVugeTBJgRquLAMyWP4axWY6mvsI1BMvDsCh9JqAW 1HT8AYmbU0K/j1C5zW6jWHkJ0Dl46vzwg37mYINKSGMCDGlpOyIMurG7VrKTbFEIJDJG oTrHEA3PepZR0ryj/3SDwC4qRnZZUdIpheFwengWiiTXtV271ekd3cuNLAWnMdf+zo+G QWLA==
MIME-Version 1.0
X-Received by 10.68.183.164 with SMTP id en4mr7660983pbc.169.1389029081245; Mon, 06 Jan 2014 09:24:41 -0800 (PST)
In-Reply-To <c552f556-4753-42dc-a2ae-e9d974f33949@googlegroups.com>
References <c552f556-4753-42dc-a2ae-e9d974f33949@googlegroups.com>
Date Tue, 7 Jan 2014 04:24:41 +1100
Subject Re: class inheritance python2.7 vs python3.3
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5037.1389029091.18130.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389029091 news.xs4all.nl 2871 [2001:888:2000:d::a6]:47591
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63310

Show key headers only | View raw


On Tue, Jan 7, 2014 at 4:14 AM,  <jwe.van.dijk@gmail.com> wrote:
> class LPU3(LPU1):
>         def __new__(self):
>         """
>         the same functions as LPU1 but some added functions
>         and some functions redefined
>         """

You probably don't want to be using __new__ here. Try using __init__
instead, or simply not defining __new__ at all.

I suspect that the reason that appears to work under Py2 is that
you're using an old-style class, there. That means it'll be subtly
different on the two versions. To make them do the same thing,
explicitly subclass object:

class LPU1(object):

In Python 3, that's redundant - subclassing object is the default. In
Python 2, though, it's important.

ChrisA

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


Thread

class inheritance python2.7 vs python3.3 jwe.van.dijk@gmail.com - 2014-01-06 09:14 -0800
  Re: class inheritance python2.7 vs python3.3 Chris Angelico <rosuav@gmail.com> - 2014-01-07 04:24 +1100
  Re: class inheritance python2.7 vs python3.3 Dave Angel <davea@davea.name> - 2014-01-06 12:46 -0500
  Re: class inheritance python2.7 vs python3.3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-07 05:10 +1100
  Re: class inheritance python2.7 vs python3.3 jwe.van.dijk@gmail.com - 2014-01-06 12:57 -0800

csiph-web