Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.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
元组解包与ipython shell escape相结合_Python_Bash_Ipython_Iterable Unpacking - Fatal编程技术网

元组解包与ipython shell escape相结合

元组解包与ipython shell escape相结合,python,bash,ipython,iterable-unpacking,Python,Bash,Ipython,Iterable Unpacking,如何在ipython中解压缩shell转义的输出 示例(工程): 但这不起作用: In [4]: hgrc0, *rest = !locate .hgrc File "<ipython-input-4-e8900264b4a8>", line 1 hgrc0, *rest = !locate .hgrc ^ SyntaxError: invalid syntax [4]中的:hgrc0,*rest=!找到hgrc 文件“”,第1行

如何在ipython中解压缩shell转义的输出

示例(工程):

但这不起作用:

In [4]: hgrc0, *rest = !locate .hgrc
  File "<ipython-input-4-e8900264b4a8>", line 1
    hgrc0, *rest = !locate .hgrc
                   ^
SyntaxError: invalid syntax
[4]中的
:hgrc0,*rest=!找到hgrc
文件“”,第1行
hgrc0,*rest=!找到hgrc
^
SyntaxError:无效语法
也不起作用:

In [13]: x = !locate .hgrc | head -1

In [14]: x
Out[14]: ['/home/wim/.hgrc']

In [15]: x, = !locate .hgrc | head -1
  File "<ipython-input-15-524d2c9ab16f>", line 1
    x, = !locate .hgrc | head -1
         ^
SyntaxError: invalid syntax
[13]中的
:x=!定位.hgrc |头-1
在[14]:x中
Out[14]:['/home/wim/.hgrc']
在[15]:x,=!定位.hgrc |头-1
文件“”,第1行
x、 =!定位.hgrc |头-1
^
SyntaxError:无效语法

Python 3.3.2+上的IPython 0.13.2

Icky,但对于这种特殊情况:

hgrc0, _ = !locate .hgrc | head -1 | printf '%s\n_' $(cat)

在我提交了一份申请后不久,这个问题就得到了解决


确认一下,您确定您使用的是Python 3吗?根据我的测试,第二个例子似乎有效。我会继续尝试,但IPython现在正在出错…[事实上,在历史结束时按下Down键时似乎就会发生这种情况]谢谢,它有效,尽管我并不真正理解那里发生了什么。事实上,如果返回了两行,那么简单的解包就行了(例如,
x,y=!locate.hgrc
),似乎只有一个元素的解包不起作用。还有splat解包。显然,IPython在其解包语法中不支持这一点。(也许值得一个bug文件?)好的,我已经在github上提交了一个文件,让我们看看会发生什么@minitech,segfaulting似乎是readline 6.3中的一个bug。
hgrc0, _ = !locate .hgrc | head -1 | printf '%s\n_' $(cat)