与ipython-shell-escap结合的Tuple解包

2024-05-29 02:56:04 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在ipython中解压shell escape的输出?在

实例(作品):

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'

但这行不通:

^{pr2}$

同样不起作用:

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

python3.3.2+上的IPython 0.13.2。在


Tags: 实例insharehomeusripythonshellout

热门问题