Whenever you assign a value to a variable in a given scope, the variable is assumed to be local to that scope. Depending on which Python you are using, you will either need to use nonlocal (Python 3) or pass the values in using parameters (Python 2).
Here is Python 2:
def toFloat(puntosX, aproxY, puntosY): # now the names of the enclosing function can be passed to the toFloat function
puntosX = [float(x) for x in puntosX]
aproxY = [float(y) for y in aproxY]
puntosY = [float(y) for y in puntosY]
In Python 3:
def toFloat():
nonlocal puntosX, aproxY, puntosY # the names now refer to the enclosing scope rather than the local scope
puntosX = [float(x) for x in puntosX]
aproxY = [float(y) for y in aproxY]
puntosY = [float(y) for y in puntosY]
global
will NOT work in this situation, since you are referencing the names of an enclosing function.
One more thing, you MAY be trying to assign new values to the names in the enclosing scope. Your present tactic will not work, since you are assigning new objects to these names within the innermost function. (List comprehensions create new lists.) If you need to keep the new values, you will need to (for example) return these values to the enclosing scope and reassign your original names to the new values. For example, in Python 2:
def taylorVazquez(fx,a,b,n,puntos):
puntosX = linspace(a,b,num=puntos)
aproxY = []
puntosY = []
def toFloat(puntosX, aproxY, puntosY): # now the names of the enclosing function can be passed to the toFloat function
puntosX = [float(x) for x in puntosX]
aproxY = [float(y) for y in aproxY]
puntosY = [float(y) for y in puntosY]
return puntosX, aproxY, puntosY
puntosX, aproxY, puntosY = toFloat(puntosX, aproxY, puntosY) # now you can reassign these names to the new values
Unlike global
, you cannot assign new values to these names and have them hold for the enclosing scope.