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

References <c552f556-4753-42dc-a2ae-e9d974f33949@googlegroups.com>
Date 2014-01-07 04:24 +1100
Subject Re: class inheritance python2.7 vs python3.3
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5037.1389029091.18130.python-list@python.org> (permalink)

Show all headers | 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