元组拆开包装与Ipython Shell逃生



如何解开ipython中的shell逃生的输出?

示例(工作):

In [1]: !locate .hgrc
/home/wim/.hgrc
/usr/share/doc/mercurial-common/examples/sample.hgrc
In [2]: hgrcs = !locate .hgrc
In [3]: hgrcs[0]
Out[3]: '/home/wim/.hgrc'

但这不起作用:

In [4]: hgrc0, *rest = !locate .hgrc
  File "<ipython-input-4-e8900264b4a8>", line 1
    hgrc0, *rest = !locate .hgrc
                   ^
SyntaxError: invalid syntax

也不起作用:

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

ipython 0.13.2在Python 3.3.2 上。

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

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

我提交问题后不久就解决了。

https://github.com/ipython/ipython/pull/5321

相关内容

  • 没有找到相关文章

最新更新