Python下划线变量 [英] Python underscore variable

查看:38
本文介绍了Python下划线变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在交互式python中,有延续变量",下划线.

<预><代码>>>>导入网络库>>>netdev = netlib.netface('eth1')>>>如果 netdev.getIP():... 打印 _...10.80.22.100>>>

但是在脚本中使用它,它是未定义的,所以失败了:

if netdev.getIP(): SetValue('ipaddress', _)

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

解决方案

没有.它仅在 Python REPL 中可用.

In interactive python, there is the 'continuation variable', the underscore.

>>> import netlib
>>> netdev = netlib.netface('eth1')
>>> if netdev.getIP():
...    print _
... 
10.80.22.100
>>>

But using this in a script, it is undefined so this fails:

if netdev.getIP(): SetValue('ipaddress', _)

Is there something similar or a way to enable this for scripts?

解决方案

No. It is only available within the Python REPL.

这篇关于Python下划线变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆