参见以下示例:
[STEP 103] # cat -n foo.py
1 def func():
2 v = another_func()
3 print v
4
5 func()
[STEP 104] # pdb foo.py
> /root/tmp/foo.py(1)<module>()
-> def func():
(Pdb) break 2
Breakpoint 1 at /root/tmp/foo.py:2
(Pdb) cont
> /root/tmp/foo.py(2)func()
-> v = another_func()
(Pdb) v = 123 <-- manually create the var
(Pdb) jump 3 <-- skip another_func()
> /root/tmp/foo.py(3)func()
-> print v
(Pdb) next
UnboundLocalError: "local variable 'v' referenced before assignment"
> /root/tmp/foo.py(3)func()
-> print v
(Pdb)
如果v
中没有创建var func()
,那么它在哪里?