Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么类字段可以在一个类方法中调用,而不能在另一个类方法中调用?_Python - Fatal编程技术网

Python 为什么类字段可以在一个类方法中调用,而不能在另一个类方法中调用?

Python 为什么类字段可以在一个类方法中调用,而不能在另一个类方法中调用?,python,Python,我有一门课看起来像这样: class Sha3_224(): def __init__(self): self.keccak = keccak.Keccak_f(b = 1600) self.sponge = sponge.Sponge(f = self.keccak, pad = sha3_hash_byte_padding, r = 1600 - 2*224, d = 224) self.digest = bytearray(0) def process(s

我有一门课看起来像这样:

class Sha3_224():
  def __init__(self):
    self.keccak = keccak.Keccak_f(b = 1600)
    self.sponge = sponge.Sponge(f = self.keccak, pad = sha3_hash_byte_padding, r = 1600 - 2*224, d = 224)
    self.digest = bytearray(0)

  def process(self, fd):
    fd.seek(0, 2)
    message = msg.Message(l = fd.tell(), fd = fd)
    fd.seek(0, 0)

    del(self.digest[0:len(self.digest)])
    self.sponge.process(msg = message, out = self.digest)

    print(self.digest)
    print(len(self.digest))

  def digest():
    print(self.digest)
当我实例化一个对象时,我可以毫无问题地调用它的
过程
方法,但是当我尝试调用它的
摘要
方法时,我得到了

TypeError:“bytearray”对象不可调用

我还可以在
\uuu init\uuu
中无误地打印(self.digest)


有人能告诉我这种行为的原因吗?

再也没有
摘要
方法了。您已经用
摘要
属性覆盖了它。只有一个名称空间

举个简单的例子:

class test():
    def __init__(self):
        self.attr = 1
    def attr(self):
        pass

t = test()
t.attr        # 1
t.attr()      # TypeError: 'int' object is not callable
test.attr     # <unbound method test.attr>
test.attr(t)  # works
class test():
定义初始化(自):
self.attr=1
def attr(自我):
通过
t=测试()
t、 属性1
t、 attr()#TypeError:'int'对象不可调用
test.attr#
测试。属性(t)#工作

不再有
摘要
方法了。您已经用
摘要
属性覆盖了它。只有一个名称空间

举个简单的例子:

class test():
    def __init__(self):
        self.attr = 1
    def attr(self):
        pass

t = test()
t.attr        # 1
t.attr()      # TypeError: 'int' object is not callable
test.attr     # <unbound method test.attr>
test.attr(t)  # works
class test():
定义初始化(自):
self.attr=1
def attr(自我):
通过
t=测试()
t、 属性1
t、 attr()#TypeError:'int'对象不可调用
test.attr#
测试。属性(t)#工作

摘要实例属性(在
\uuuuu init\uuuuu
中设置)隐藏摘要方法。您必须重命名实例属性或方法。

摘要实例属性(在
\uuuuu init\uuuuuu
中设置)隐藏了摘要方法。您必须重命名实例属性或方法。

实际上,
摘要
方法仍然存在,但只能在类中查找…很明显,这是我的耻辱-。-。实际上,
摘要
方法仍然存在,但只能在类中查找…很明显,我真是太遗憾了。