Python ';int';类中的对象不可调用错误

Python ';int';类中的对象不可调用错误,python,Python,在Python2.7中,我正在编写一个名为Zillion的类,它充当非常大的整数的计数器。我相信我已经把它弄清楚了,但我一直遇到TypeError:“int”对象是不可调用的,这似乎意味着在我的代码中的某个点上,我试图调用int,就像它是一个函数一样。我在这个网站上发现的许多例子都只是一个数学错误,作者省略了一个操作符。我似乎找不到我的错误 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 z、 增量() TypeError:“int”对象不可调用 我的代码: class Zillion:

在Python2.7中,我正在编写一个名为
Zillion
的类,它充当非常大的整数的计数器。我相信我已经把它弄清楚了,但我一直遇到
TypeError:“int”对象是不可调用的
,这似乎意味着在我的代码中的某个点上,我试图调用
int
,就像它是一个函数一样。我在这个网站上发现的许多例子都只是一个数学错误,作者省略了一个操作符。我似乎找不到我的错误

回溯(最近一次呼叫最后一次):
文件“”,第1行,在
z、 增量()
TypeError:“int”对象不可调用
我的代码:

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
class-Zillion:
定义初始化(自身,数字):
self.new=[]
self.count=0#用于过程和增量
self.increment=1#用于增量
def过程(自身,数字):
如果数字=“”:
引发运行时错误
elif数字[0]。isdigit()==假:
如果数字[0]=''或数字[0]='',则:
数字=数字[1:]
其他:
引发运行时错误
elif数字[0]。isdigit():
self.new.append(int(数字[0]))
数字=数字[1:]
self.count+=1
如果数字!='':
进程(自身,数字)
进程(自身,数字)
如果self.count==0:
引发运行时错误
self.new2=self.new#用于isZero
def toString(自):
self.mystring=''
self.x=0
当self.x
您既有一个实例变量,又有一个名为
increment
的方法,这似乎是您的回溯问题

\uuuu init\uuuu
中定义
self.increment=1
,并使用相同的名称屏蔽方法

要修复,只需重命名其中一个(如果是变量名,请确保更改所有使用它的位置,就像整个
increment
方法一样)

查看此处发生的情况的一种方法是使用
类型
进行调查。例如:

>>> type(Zillion.increment)
<type 'instancemethod'>
>>> z = Zillion('5')
>>> type(z.incremenet)
<type 'int'>
>>类型(Zillion.increment)
>>>z=Zillion('5')
>>>类型(z.incremenet)

您已经在
Zillion中定义了一个实例变量。\uuu init\uuuu()

然后您定义了一个名为“Zillion.increment()”的方法:

因此,如果您尝试像这样调用您的方法:

big_number = Zillion()
big_number.increment()

.ìincrement
将是您在
中定义的整数,而不是方法。

因为您有一个变量成员
self.increment
,并且它已在
\uu init\uu
函数中设置为1

z.increment
表示设置为1的变量成员


您可以将函数从
increment
重命名为
\u increment
(或任何其他名称),它将正常工作

错误发生在哪一行?除非您能告诉我们错误发生在哪里,否则代码转储是没有用的。如果没有所有的信息回溯(最近一次调用last),我们不会尝试模拟您的错误:文件“”,第1行,在z.increment()TypeError中:“int”对象是不可调用的,我把它放在最上面,man
z
必须是整数,而不是
Zillion
类的实例。无法从回溯中看出您是如何定义它的。
def increment(self):
    […]
big_number = Zillion()
big_number.increment()