[IPython-user] alias / macro question

Ville M. Vainio vivainio at gmail.com
Fri Dec 1 03:55:35 CST 2006

On 12/1/06, belinda thom <bthom at cs.hmc.edu> wrote:

> I would like to be able to bundle the following commands into a
> single command:
> import <foo>; reload(<foo>); from <foo> import *
> where <foo> is treated like an argument (its text value replaces foo).
> At first I thought %alias might work, but alas, the manual tells me
> it is only for system shell commands.

You could try something like:

[environmentswitch]|2> m = 'os'
[environmentswitch]|3> _ip.ex('import ' + m)
[environmentswitch]|4> %macro do_imp 3
Macro `do_imp` created. To execute, type its name (without quotes).
Macro contents:
_ip.ex('import ' + m)

[environmentswitch]|6> m = 'sys'
[environmentswitch]|7> do_imp
                   <7> Executing Macro...

Ville M. Vainio - vivainio.googlepages.com
blog=360.yahoo.com/villevainio - g[mail | talk]='vivainio'

More information about the IPython-user mailing list