Python下划线变量

tMC*_*tMC 3 python variables

在交互式python中,有一个'continuation variable',下划线.

>>> import netlib
>>> netdev = netlib.netface('eth1')
>>> if netdev.getIP():
...    print _
... 
10.80.22.100
>>>
Run Code Online (Sandbox Code Playgroud)

但是在脚本中使用它,它是未定义的,因此失败:

if netdev.getIP(): SetValue('ipaddress', _)
Run Code Online (Sandbox Code Playgroud)

是否有类似的东西或方法为脚本启用此功能?

Ign*_*ams 9

不可以.它仅在Python REPL中可用.