有没有办法在python中实现以下内容:
def print_loop_var():
loop_var = fn_inspect_frame_stack()
print "The loop variable is: %s" % loop_var
for k in mylist1:
print_loop_var()
for m in mylist2:
print_loop_var()
输出:
The loop variable is: k
The loop variable is: m
The loop variable is: m
...
The loop variable is: k
The loop variable is: m
The loop variable is: m
...
对于我的应用程序,我无法将参数传递给print_loop_var()
。
除了名称,我也会对变量的内容感到满意。