我最近开始学习 python(来自 C++ 背景),但我不明白我应该如何访问成员变量 ( nonce) 并在名为def mine_block().class Block: ''' Дефинираме ф-я , която създава променливите като членове на класа Block ''' def _init_(self,prevHash,index,nonce,data,hash,time): self.prevHash = prevHash self.index = index self.nonce = nonce self.data = data self.hash = hash self.time = time def get_hash(self): print(self.hash) def mine_block(self,difficulty): arr = [] for i in range(difficulty): arr[i] = '0' arr[difficulty] = '\0' str = arr while True: ''' here I receive an error unresolved referene nonce ''' nonce++
2 回答
ITMISS
TA贡献1871条经验 获得超8个赞
在 Python 中,所有实例成员都是通过类实例公开可用的,该类实例作为self. 因此你应该使用self.nonce.
此外,在 Python 中要小心缩进。您的 mine_block 方法应如下所示:
def mine_block(self,difficulty):
...
str = arr
while True:
self.nonce += 1
添加回答
举报
0/150
提交
取消