Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python下划线变量_Python_Variables - Fatal编程技术网

Python下划线变量

Python下划线变量,python,variables,Python,Variables,在交互式python中,有一个“continuation变量”,即下划线 >>> import netlib >>> netdev = netlib.netface('eth1') >>> if netdev.getIP(): ... print _ ... 10.80.22.100 >>> 但在脚本中使用此选项时,它是未定义的,因此此操作失败: if netdev.getIP(): SetValue('ipadd

在交互式python中,有一个“continuation变量”,即下划线

>>> import netlib
>>> netdev = netlib.netface('eth1')
>>> if netdev.getIP():
...    print _
... 
10.80.22.100
>>>
但在脚本中使用此选项时,它是未定义的,因此此操作失败:

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

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

否。它仅在Python REPL中可用。

Bummer!我想,我只是希望有一个干净的工作环境或其他选择。谢谢:)“清洁工作环境”?这不是赋值语句吗?我必须设置很多值-我只是希望将每个函数保持在一行-而不使其过长或难以阅读。我想出了一个清晰的方法来写它。谢谢=)