What is the best way to append and clear the list deriv_position = [] from inside the function test?
I got NameError: name 'deriv_position' is not defined
class TestClass:
deriv_position = []
def test():
if len(deriv_position) > 0:
print("trade is open")
deriv_position.clear()
else:
print("trade is close")
deriv_position.append("1")
test()
test.deriv_positiontestisn't helping. And it's unclear why that's in a class at all, if you're going to call the method immediately inside the class definition.classstatement does not establish a new scope, but neither do assignments in a class statement modify the enclosing scope. The namespace created by a class statement is outside the hierarchy of scopes in Python.