def a():
def b():
print "b"
print "a"
return b
>>>x=a()
a
>>>x()
b
- 追問
這個辦法固然不錯,但是我這是這樣的:(調用a()是返回一個<functin b at xxxxx>),這不是我想看見的。
- 回答
def b()只在def a()內部的scope纔可見,你必須在這個scope裏把b的reference傳遞出來,纔可能在這個scope之外的地方調用b。
def a():
def b():
print "b"
print "a"
return b
>>>x=a()
a
>>>x()
b
這個辦法固然不錯,但是我這是這樣的:(調用a()是返回一個<functin b at xxxxx>),這不是我想看見的。
def b()只在def a()內部的scope纔可見,你必須在這個scope裏把b的reference傳遞出來,纔可能在這個scope之外的地方調用b。
繼續運行 ?* 回憶上次內容 上次使用shell環境中的命令 命令 作用 c