如何在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
Python 3.3.2上的IPython 0.13.2.
解决方法:
Icky,但对于这个特例:
hgrc0, _ = !locate .hgrc | head -1 | printf '%s\n_' $(cat)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。