Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tuple unpacking combined with ipython shell escape

How can I unpack the output of a shell escape in ipython?

Example (works):

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'

But this doesn't work:

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

Also not working:

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 on Python 3.3.2+.

like image 819
wim Avatar asked Mar 21 '23 16:03

wim


1 Answers

Icky, but for this particular case:

hgrc0, _ = !locate .hgrc | head -1 | printf '%s\n_' $(cat)
like image 98
Ry- Avatar answered Apr 02 '23 11:04

Ry-