compile error when using override

Steve D'Aprano steve+python at
Fri Dec 2 00:02:04 EST 2016

On Fri, 2 Dec 2016 01:35 pm, Ho Yeung Lee wrote:

> from __future__ import division
> import ast
> from sympy import *
> x, y, z, t = symbols('x y z t')
> k, m, n = symbols('k m n', integer=True)
> f, g, h = symbols('f g h', cls=Function)
> import inspect

Neither ast nor inspect is used. Why import them?

The only symbols you are using are x and y.

> def op2(a,b):
>     return a*b+a

This doesn't seem to be used. Get rid of it.

> class AA(object):
>     @staticmethod
>     def __additionFunction__(a1, a2):
>         return a1*a2 #Put what you want instead of this
>     def __multiplyFunction__(a1, a2):
>         return a1*a2+a1 #Put what you want instead of this
>     def __divideFunction__(a1, a2):
>         return a1*a1*a2 #Put what you want instead of this

None of those methods are used. Get rid of them.

>     def __init__(self, value):
>         self.value = value
>     def __add__(self, other):
>         return self.value*other.value

Sorry, you want AA(5) + AA(2) to return 10?

>     def __mul__(self, other):
>         return self.value*other.value + other.value
>     def __div__(self, other):
>         return self.value*other.value*other.value
> solve([AA(x)*AA(y) + AA(-1), AA(x) + AA(-2)], x, y)

I don't understand what you are trying to do here. What result are you

Maybe you just want this?

from sympy import solve, symbols
x, y = symbols('x y')
print( solve([x*y - 1, x - 2], x, y) )

which prints the result:
[(2, 1/2)]

Perhaps if you explain what you are trying to do, we can help better.

But please, cut down your code to only code that is being used!

“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

More information about the Python-list mailing list