[IPython-user] Running ipython from shell with pylab

Gökhan SEVER gokhansever@gmail....
Sat May 9 14:27:59 CDT 2009


Ok, replying my own question :)

I have solved everything but one issue with the following code snippets:


import IPython
from sys import argv
argv.insert(2, '--pylab')
ipython = IPython.Shell.start()
ip = IPython.ipapi.get()
ip.ex('a = 5')
ip.IP.magic_run(argv[1])
ipython.mainloop()

where it is in splot.py file. And I call it as:    splot.py m.py

# m.py contents:

import matplotlib.pyplot as plt
x = [1,2,3]
plt.plot(x)
plt.show()

The only question is after magic_run executes the script, my current
namespace only contains the variable "a" However x is there but not listed
with "whos" command.

Could you please tell me how can I collect them under one visible namespace?

Thank you again.
Gökhan


On Fri, May 8, 2009 at 4:59 PM, Gökhan SEVER <gokhansever@gmail.com> wrote:

> Hello,
>
> I would like write a simple script which will be called from a Bash shell,
> and initiate an IPython matplotlib enabled session, and will run an external
> file as is supplied in command argument within the same session.
>
> A simple demonstration:
>
> 1- plot m.py
> 2- start an Ipython with pylab
> 3- run the m.py script
> 4- show figure(s)
> 5- maintain namespace and stay inside the Ipython
>
> I have written a few lines which doesn't work the way I want it to be as
> given below:
>
> #!/usr/bin/env python
>
> from sys import argv
> argv.insert(2,'--pylab')
> import IPython
> ipython = IPython.Shell.start()
> ip = IPython.ipapi.get()
> ip.IP.magic_run(argv[1])
> ipython.mainloop()
>
> for some reason the external file isn't run :(
>
> Could you please help me on this issue?
>
> Thank you
>
> Gökhan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20090509/79a993d5/attachment.html 


More information about the IPython-user mailing list