[IPython-user] Macros & slice notation

Fernando Perez Fernando.Perez at colorado.edu
Fri Dec 30 12:34:34 CST 2005


skip at pobox.com wrote:
>     >> we could change the range syntax in %macro and %save to use 
>     >> N-M
> 
>     Alan> Maybe N--M?
> 
>     >> instead of N:M 
> 
> I'm not exactly sure of the Python context where these will be operational,
> but both n-m and n--m are already valid Python expressions:
> 
>     >>> n=3
>     >>> m=-7
>     >>> n--m
>     -4
>     >>> 3---7
>     -4

Not to worry: these are processed only for magics, so the arguments are 
treated separately, and not as python expressions.

This is precisely an example of why I've argued on python-dev, on the 
quit/exit thread, that a good interactive shell needs a control system which 
is separate from the underlying language (in this case, python).

In ipython, the control commands are the %magics, and I've tried to make them, 
in usage, as similar to shell commands as possible (--flags, ~filenames are 
expanded, whitespace for all argument separation, etc).  This makes getting 
into ipython, hopefully, an easy process.  I've tried to make the resulting 
environment one that offers, within reason:

1. Normal python execution as expected, but better (tab, ?, tracebacks, pdb, etc.)

2. Seamless access with the OS: aliases, !cmds.

3. The benefits of python scripting for OS tasks: $vars

4. A way to interactively control ipython itself: %magics.  These are normally 
accessed without %, but it's important to have a disambiguation character, so 
they remain _always_ accessible even when shadowed by python variables.


Regards,

f




More information about the IPython-user mailing list