Pythonで次のスタッククラスを使用して、別のクラスのオブジェクトを格納しました。
class Stack :
def __init__(self) :
self.items = []
def push(self, item) :
self.items.append(item)
def pop(self) :
return self.items.pop()
def isEmpty(self) :
return (self.items == [])
scopeStack=Stack();
object1=AnotherClass();
object1.value=2;
scopeStack.push(object1);
スタック外のオブジェクトobject1の内容を変更すると、スタックのオブジェクトの内容も変更されました。
object1.value=3;
obj=scopeStack.pop();
print obj.value; #gives output 3
ローカル変数とスタックの内部変数の間にこの動的なバインディングがないようにするにはどうすればよいですか?