hashlib在python中编写区块链
我正在尝试创建一个区块链。运行时,我收到以下错误:hashlib在python中编写区块链,python,Python,我正在尝试创建一个区块链。运行时,我收到以下错误: " File "<ipython-input-3-7d6dab8d7cb5>", line 50 content_hash= hashlib.sha256(content).hexdigest() ^ SyntaxError: invalid syntax" 错误实际上是前几行的结果。它们没有正确关闭(您忘记了结束括号“}”)…因此解释器试图将下一行包含在它们中,并且不知道如何执行 更正:
" File "<ipython-input-3-7d6dab8d7cb5>", line 50
content_hash= hashlib.sha256(content).hexdigest()
^
SyntaxError: invalid syntax"
错误实际上是前几行的结果。它们没有正确关闭(您忘记了结束括号“}”)…因此解释器试图将下一行包含在它们中,并且不知道如何执行 更正:
def valid_proof(self, index, hash_of_previous_block, transactions, nonce):
#create a string containing the hash of the previous block and the block content, including the nonce
content ={
f'{index}{hash_of_previous_block}{transactions}{nonce}'.encode()
}
#hash using sha256
content_hash = hashlib.sha256(content).hexdigest()
您从未关闭过花括号
content={
,直到返回后,您才可以这样做
def valid_proof(self, index, hash_of_previous_block, transactions, nonce):
#create a string containing the hash of the previous block and the block content, including the nonce
content ={
f'{index}{hash_of_previous_block}{transactions}{nonce}'.encode()
}
#hash using sha256
content_hash = hashlib.sha256(content).hexdigest()