メソッドを呼び出すときにエラーが発生しましたが、メソッドが呼び出されるオブジェクトがそのメソッドを定義します。メソッドが呼び出されるのはここバインドされていないメソッドを呼び出すときにタイプエラーが発生しましたが、クラス_does_がそのメソッドを定義しました
は次のとおりです。
def interpreter(self, ast, expression, stack) # method in Parser.py file
...
elif isinstance(ast, ReadNode):
self.interpret(ast.location, environment, stack)
loc = stack.pop()
input = sys.stdin.read()
try:
num = int(input)
except:
sys.stderr.write("error: not an integer")
loc.set(num)
...
私はここでloc.set(num)
Traceback (most recent call last):
File "/home/filepath/Parser.py", line 846, in <module>
main()
File "/home/filepath/Parser.py", line 844, in main
p.parse()
File "/home/filepath/Parser.py", line 75, in parse
self.interpret(instructions, environment, stack)
File "/home/filepath/Parser.py", line 128, in interpret
loc.set(num)
TypeError: unbound method set() must be called with IntegerBox instance as first argument (got int instance instead)
上のエラーを取得していますIntegerBoxクラスです:
from Box import Box
class IntegerBox(Box):
def __init__(self, value=0):
self.value = value
def get(self):
return self.value
def set(self, value):
self.value = value
私が通過した場合デバッガはloc
の種類を確認するには、それはですインスタンス。 loc
がIntegerBoxのインスタンスではないと思われるのはなぜですか?
あなたは 'interpret'のコードを表示する必要があります。好奇心から外に – BrenBarn