Strange error, possibly related to var

asked 2012-04-04 16:16:44 -0500

chaesloc2 gravatar image

updated 2012-04-04 16:21:11 -0500

class CTest(object):
    def __init__(self,arg=None):
        if type(arg) is list:
            print [x in ZZ for x in arg]
        elif arg in PolynomialRing(ZZ,2,(x,y)):

Traceback (most recent call last):
  File "", line 6, in __init__
UnboundLocalError: local variable 'x' referenced before assignment

Replacing var('x,y') with x,y=var('x,y') eliminates the error. So does replacing PolynomialRing(ZZ,2,(x,y)) with [1,2,3]. Or changing the x in [x in ZZ for x in arg] to z.

edit retag flag offensive close merge delete



I believe this is Python local versus global variable thing. `var('x y')` injects `x` and `y` into the "global namespace", but Python considers all variables talked about inside a function to be "local", even if they have the same names. (This is good or bad, depending on whom you ask.) But I couldn't isolate the exact problem either, frustrating. Maybe this will help anyway?

kcrisman gravatar imagekcrisman ( 2012-04-05 05:56:19 -0500 )edit