[IPython-user] Fairly deep changes in CVS, testers welcome

Fernando Perez Fernando.Perez at colorado.edu
Thu Jun 24 13:57:43 CDT 2004


Ville Vainio wrote:
> On Mon, Jun 21, 2004 at 01:58:21AM -0600, Fernando Perez wrote:

>  > The only really major thing missing from pysh to be usable as a light 
> shell
>  > (I don't claim it to be in the same league as bash/tcsh) is that all of
>  > this magic only applies for single-line statements.  If you want to write
>  > multi-line code, you still need to call system() yourself and do your own
>  > variable expansions.
> 
> Is there a particular reason for this? Couldn't the same expansion routines
> be applied to all lines that start with "!" or "!!"? The need for this is
> very typical in cases like:
> 
>  >>>> !!find . | grep wav
> 
> (verify that files are correct)
> 
>  >>>> wavs = _
> 
>  >>>> for w in wavs:
> ....   !oggenc $w

Well, the time machine strikes again :)  In my private copy I actually have it 
working:

fperez[~]|1> cd test
fperez[~/test]|2> $$a=ls
fperez[~/test]|3> for f in a:
               |.>     wc -l $f
               |.>
4 argv.py
1 bar.py
2 bar.pyc
9 die.py
14 div.c
14 div.f
3 div.py
113 error.py

I need to clean some things before this goes into CVS, it's not ready even for 
that yet.

The $ syntax is a pysh-only extension (not for normal IPython) which does:

$var=cmd <=> @sc var=cmd and  $$var=cmd <=> @sc -l var=cmd

Very useful for rapidly building _python_ variables from shell output.

In multiline input, only aliases and ! will be allowed, not magics or !!. 
Magics are too tied to controlling ipython itself, so it doesn't make sense to 
run them in a python loop.  And !! is meant to return a value into a list, but 
I don't want to allow something like

	a=!!ls

that's just gross.  In case you need list-split output inside a loop, I added 
a 'split' keyword argument to getoutput(), so this works: 
getoutput('ls',split=1) will give you a newline-split list.

I made up

sout = lambda cmd: getoutput(cmd,split=1)

and stuck it into my ipythonrc file, so I can say inside a loop:

   alist = sout('ls')

and then operate on alist as needed.

>  > In particular, @rehash/x are very Unix-specific.  I don't know how to 
> deal
>  > with $PATH and how to make executability decisions under Windows, 
> which (I
>  > think) has a baroque extension-based mechanism for this.  If someone else
> 
> Why don't you just make some well-known extensions executable? exe, bat,
> cmd, py, pl? It's much better than nothing, and works for 99% of the cases.

See Dang's comment.  Together with some code sent privately by Gary Bishop, 
the issue for Win users should be ok, once I commit (in a couple of days).

> I'll try to check it out (literally) after midsummer routines, though my
> familiarity with ipython (codebase and in general) possibly isn't good
> enough to make informed judgements just yet. Apparently ipython is just now
> starting to address my needs, it's just good to see that you have
> interest/ambition to invade the shell domain after all :-).

Well, I wasn't planning on it.  But I recently realized that once the alias 
infrastructure was cleaned up, it really was much less work than I'd 
originally thought.  And now I'm using it as my shell, which is really nice :)

Cheers,

f




More information about the IPython-user mailing list