Python区块链。名称错误:名称';链';没有定义
今天我正在用python构建一个区块链,因为我对加密货币感兴趣。当我遇到这个错误时,我正准备启动它Python区块链。名称错误:名称';链';没有定义,python,Python,今天我正在用python构建一个区块链,因为我对加密货币感兴趣。当我遇到这个错误时,我正准备启动它 Traceback (most recent call last): File "blockchain.py", line 9, in <module> class Chain(object): File "blockchain.py", line 17, in Chain blockchain = Chain() NameError: name 'Chain' is not defi
Traceback (most recent call last):
File "blockchain.py", line 9, in <module>
class Chain(object):
File "blockchain.py", line 17, in Chain
blockchain = Chain()
NameError: name 'Chain' is not defined
如果您需要更多的代码,那么我不介意提供更多。
提前谢谢 IIUC您试图调用类
链之外的区块链=Chail()
。你的缩进是错的。这应该行得通
class Chain(object):
def __init__(self):
self.chain = []
self.current_transactions = []
self.new_block(previous_hash=1, proof=100)
app = Flask(__name__)
node_indentifier = str(uuid4()).replace('-', '')
blockchain = Chain()
它就像缩进一样简单。
你写的
chain=chain()
在课堂上。正确的代码只是将最后一行向后移动
import hashlib
import json
from textwrap import dedent
from time import time
from hashlib import sha256
from uuid import uuid4
from flask import Flask, jsonify, request
class Chain(object):
def __init__(self):
self.chain = []
self.current_transactions = []
self.new_block(previous_hash=1, proof=100)
app = Flask(__name__)
node_indentifier = str(uuid4()).replace('-', '')
blockchain = Chain()
最后几行都在类中,因为它们是缩进的。也许它们不应该在你的类内。你的意思是在类外调用blockchain=Chain()
?
import hashlib
import json
from textwrap import dedent
from time import time
from hashlib import sha256
from uuid import uuid4
from flask import Flask, jsonify, request
class Chain(object):
def __init__(self):
self.chain = []
self.current_transactions = []
self.new_block(previous_hash=1, proof=100)
app = Flask(__name__)
node_indentifier = str(uuid4()).replace('-', '')
blockchain = Chain()