[IPython-user] capture shell output with '!!'

Ryan Krauss ryanfedora at comcast.net
Wed Aug 31 07:37:32 CDT 2005


glob is the python module you want:

In [186]: import glob

In [187]: test=glob.glob('*.py')

In [188]: test
Out[188]:
['rigid_link_AVS.py',
  'two_carts.py',
  'three_carts.py',
  'nra_test.py',
  'three_carts_wrap.py',
  'loop_dev.py',
  'noncolocated.py',
  'parse_test.py',
  'environ_test.py',
  'samii_model.py']

In [189]:

Rakotomandimby Mihamina wrote:
> Hi,
> I saw in the documentation, a while ago, some tips to capture the output
> of a shell command to a variable (a list)
> 
> I lost it (the location), and now i'm obliged to use %sc.
> 
> My needs:
> - I got some mp3/ogg songs from a friend
> - The directories and file names contain spaces
> - I need to rename thoses files and directories to spaceless names,
> replacing spaces with underscore.
> - I use the 'find' of the system and it returns a list of paths.
> (BTW: is there any internal 'find' into python or ipython?)
> - I want to process each element of the list, but I need to store the
> list in a variable before, and that is I lost the documentation on.
> 
> with %sc:
> =============================================
> In [3]: %sc -l variable=ls
> 
> In [4]: variable
> Out[4]:
> ['correspondance',
>  'CPSDocumentations',
>  'Desktop',
>  'download',
>  'funk.m3u',
>  'index.html',
>  'index_vsftpd.html',
>  'index_vsftpd.html~',
>  'lip.txt',
>  'Music',
>  'Pictures',
>  'Placard',
>  'Programmation',
>  'ripped-music',
>  'signature.txt',
>  'tmp',
>  'tmp.txt',
>  'video']
> ================================================
> 
> With '!!', I get error syntaxes whatever I try, and I dont find the
> documentation.... :-(
> 
> SOme tips?




More information about the IPython-user mailing list