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

Frédéric Mantegazza mantegazza at ill.fr
Fri Mar 25 01:38:11 CST 2005


Le Mercredi 23 Mars 2005 17:48, Fernando Perez a écrit :

> If you update CVS (I just fixed a small bug in runlines()), the following
> magic will run a file containing text as if it had been typed in the
> ipython prompt:
>
> def magic_runbatch(self, parameter_s=''):
>      """ runbatch magic command.
>      """
>      try:
>          fileobj = open(parameter_s,'r')
>      except:
>          print "Error: could not open file",parameter_s
>          return
>      else:
>          self.shell.runlines(fileobj.read())

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

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.

-- 
   Frédéric




More information about the IPython-user mailing list