0
class viewer:
def setup(func):
func()
def draw(func):
func()
@viewer.setup
def set():
x = 2017
@viewer.draw
def draw():
print(x)
上述結果的代碼:Python的裝飾噩夢
Traceback (most recent call last):
File "test.py", line 13, in <module>
@viewer.draw
File "test.py", line 7, in draw
func()
File "test.py", line 15, in draw
print(x)
NameError: name 'x' is not defined
我的問題是,我怎麼能實現觀衆,使得在設置中定義的變量是平局訪問?
嘛'x'根本就不是在範圍'draw'。 –
我的問題是,我怎麼能實現瀏覽器,使得在設置中定義的變量是平局訪問? –