[IPython-user] Using runlines (was __IP.push())

Fernando.Perez at colorado.edu Fernando.Perez at colorado.edu
Fri Mar 25 02:41:25 CST 2005


Quoting Frédéric Mantegazza <mantegazza at ill.fr>:

> I've made some tests, and I can't make it work with ipython 0.6.13cvs. I
> always get an error on the second non blank line. With you test file, I
> get:
>
> In [2]:%runbatch /tmp/test.batch
> This is being run by IPython
> ------------------------------------------------------------
>    File "<console>", line 1
>      %sc a=ls i*py
>      ^
> SyntaxError: invalid syntax

Mmh, this is strange.  It certainly works for me here.  Are you sure you may not
be picking up non-CVS ipython somewhere?

> With this file:
>
> cd /home
> cd /tmp
>
> I get:
>
> In [3]:%runbatch /home/fma/.PyMAD/batch.py
> /home
> ---------------------------------------------------------------------------
> exceptions.NameError                                 Traceback (most recent
> call last)
>
> /home/<console>
>
> NameError: name 'cd' is not defined
>
> If I use %cd instead, I get a SyntaxError, like in your example. The first
> line is correctly executed, but not following.

OK, I did find a small problem here.  Please update CVS and try again.  Just to
show that I'm not making this up :), here's what I get on my system:

In [1]: cat ipbatch.py
print "This is being run by IPython"

sc a=ls i*py

print "a is:\\n",a
print "run a loop over a.l"
for f in a.l:
  print f
  !wc -l $f

3+5
print _

In [2]: runbatch ipbatch.py
This is being run by IPython
a is:\n input.py
ipbatch.py
ippush.py
iters2.py
iters3.py
iters.py
run a loop over a.l
input.py
2 input.py
ipbatch.py
12 ipbatch.py
ippush.py
22 ippush.py
iters2.py
23 iters2.py
iters3.py
19 iters3.py
iters.py
18 iters.py
Out[0]: 8
8

AND for the other one (an extension to your example):

In [1]: cat test.batch
print 1
cd /home
print 2
cd /tmp
print 3
cd /home/fperez/test
print 4

In [2]: runbatch test.batch
1
/usr/local/home
2
/tmp
3
/usr/local/home/fperez/test
4

#######

So in both cases it works.  Note the funky decrease in the prompt counter by 2,
I have no idea what's going on there.  I may have a look, but since I expect
this kind of 'batch' file running is not meant to return results, it's
low-priority.

Best,

f




More information about the IPython-user mailing list