class inheritance python2.7 vs python3.3
jwe.van.dijk at gmail.com
jwe.van.dijk at gmail.com
Mon Jan 6 15:57:05 EST 2014
On Monday, 6 January 2014 18:14:08 UTC+1, jwe.va... at gmail.com wrote:
> I have problems with these two classes:
>
>
>
> class LPU1():
>
> def __init__(self, formula):
>
> """
>
> formula is a string that is parsed into a SymPy function
>
> and several derived functions
>
> """
>
> self.formula = formula
>
> ... ...
>
>
>
> class LPU3(LPU1):
>
> def __new__(self):
>
> """
>
> the same functions as LPU1 but some added functions
>
> and some functions redefined
>
> """
>
> ... ...
>
>
>
> if __name__ == '__main__:
>
> y = y = 'x_0 * x_1 + x_2'
>
> stats1 = LPU1(y)
>
> stats3 = LPU3(y)
>
>
>
> Worked perfectly on Python 2.7.5+ but on Python 3.3.2+ I get on instantiatiating stat3:
>
> TypeError: __new__() takes 1 positional argument but 2 were given
>
>
>
> What am I doing wrong?
>
> I must confess I am a bit out of my depth here so any explanation will be a learning experience.
>
>
>
> Many thanks, Janwillem
Thanks for all the contributions. I now have:
class LPU1(object):
def __init__(self, formula):
... ...
and
class LPU3(LPU1):
def __init__(self, y):
LPU1.__init__(self, y)
... ...
which gives the correct results both on 2.7 and 3.3.
Is that more or less good practice?
Now I stumble on a SymPy problem under 3.3 but that obviously is an other topic
Cheers, janwillem
More information about the Python-list
mailing list