[IPython-dev] Magics that have return values, $$var=cmd simplification
Fernando.Perez at colorado.edu
Tue Jan 24 12:53:54 CST 2006
Ville Vainio wrote:
> I figured we could implement a handy and intuitive way to grab
> both magic return values and system command output:
> var = %mymagic args a plenty
> var = !command args a plenty
> The regexp to catch these reliably is trivial (provided that var name
> is (\w+) and both are illegal python. Anyone have any
> doubt/objections? $$var = cmd syntax is there but it's not as easy to
> remember or obvious.
+1: it looks like it can be done safely, at least in single-line input. I'd
avoid this in continuation lines, because you could be in the middle of a
string (triple-quoted). In multiline input, people can always use
foo = ipmagic()
and friends. Even for ipython, which tries as hard as possible to be
convenient, correctness trumps convenience.
I'd suggest adding a test/ directory to ipython, where we can start at least
storing primitive testing scripts. For now, even if it's just plain files
that we can copy/paste into a session to see whether we haven't totally blown
something would be good. I've many times in the past made a seemingly
innocuous change to a regexp, just to find out that I broke something
fundamental in input processing.
Having lines of valid python that we can just highlight and paste in would be
good, and it would provide a minimal measure of safety when experimenting with
extensions like this.
As time goes, this can grow into a proper unittest framework (for chainsaw, we
WILL enforce unittest coverage for all code; no reason we can't start a little
More information about the IPython-dev