[IPython-user] Capturing output from shell cmds
Fernando Perez
fperez at colorado.edu
Tue Sep 23 19:20:44 CDT 2003
Rajarshi Guha wrote:
> I recently discovered IPython and I must say thats is an amazing tool!
> I was also wondering about capturing output of shell commands and after
> looking at your post I am a little confused with execfile and import_mod
>
> I have some python code that gives me lists of combinations of
> integers. I wrote a small .py file containing the code and in my
> ipythonrc I did
>
> import_mod combo
>
> and I can then access it via combo.make_list() from the shell
> In your post you mention that the capture() code should be a magic file.
> Would there be any difference if I made my combo list function into a
> magic function (apart from less typing)?
Not really. import_mod is simply the equivalent of saying 'import combo' in
python code. If you want to import everything in combo as top-level names,
you want 'from combo import *', which in the config file is spelled
'import_all combo'
> Another related question - you mention that command.getoutput does more
> or less what capture does. Is there any way I can 'alias' the command. I
> tried
>
> alias capture command.getoutput('%s')
>
> but it does'nt work. Granted its not much to type but is it possible to
> shorten these type of function calls as I would alias a shell command?
alias is for _system_ aliases. Simply make a normal python function that does
what you want and load it as part of your startup process, and you're done.
> Thanks for a great peice of software!
Glad you like it, thanks for the feedback.
Cheers,
f.
More information about the IPython-user
mailing list