Python 2.7では、非常に大きな整数のカウンターとして機能するクラスZillion
を作成しています。私はそれが詰まっていると信じていますが、私はTypeError: 'int' object is not callable
に走り続けています。これは、コードのある時点で、私がint
を関数のように呼び出そうとしたことを意味するようです。私がこのサイトで見つけた多くの例は、作者がオペレータを省略した数学的なエラーに過ぎませんでした。私は自分の誤りを見つけることができない。クラス 'int'オブジェクトが呼び出し可能なエラーではありません
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
z.increment()
TypeError: 'int' object is not callable
マイコード:
class Zillion:
def __init__(self, digits):
self.new = []
self.count = 0 # for use in process and increment
self.increment = 1 # for use in increment
def process(self, digits):
if digits == '':
raise RuntimeError
elif digits[0].isdigit() == False:
if digits[0] == ' ' or digits[0] == ',':
digits = digits[1:]
else:
raise RuntimeError
elif digits[0].isdigit():
self.new.append(int(digits[0]))
digits = digits[1:]
self.count += 1
if digits != '':
process(self, digits)
process(self, digits)
if self.count == 0:
raise RuntimeError
self.new2 = self.new # for use in isZero
def toString(self):
self.mystring =''
self.x = 0
while self.x < self.count:
self.mystring = self.mystring + str(self.new[self.x])
self.x += 1
print(self.mystring)
def isZero(self):
if self.new2[0] != '0':
return False
elif self.new2[0] == '0':
self.new2 = self.new2[1:]
isZero(self)
return True
def increment(self):
if self.new[self.count - self.increment] == 9:
self.new[self.count - self.increment] = 0
if isZero(self):
self.count += 1
self.new= [1] + self.new
else:
self.increment += 1
increment(self)
elif self.new[self.count - self.increment] != 9:
self.new[self.count - self.increment] = self.new[self.count - self.increment] + 1
エラーは何行発生しますか?コード・ダンプは、エラーの発生場所を教えてくれないと有用ではありません。私たちは(最後の最新の呼び出し)すべての情報 – CDspace
トレースバックせずにエラーをシミュレートしようとするつもりはない: z.incrementで ファイル「」、ライン1、() はTypeError:「int型のオブジェクトではありません呼び出し可能 私はそれをトップマンに置きます。 –
'z'は整数でなければなりません。' Zillion'クラスのインスタンスではありません。あなたが定義したトレースバックからは分かりません。 – martineau