[IPython-User] Embedding IPython troubles with shell profile / runlines

Stefan Frühwirth stefan.fruehwirth@uni-graz...
Mon Jan 31 13:53:26 CST 2011


I have troubles using an embedded IPython instance. Here's how I used it:

from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(['-p', 'sh'])

First, when I call ipshell(), which should result in getting an embedded 
IPython prompt, a blank line is printed and the calling script exits. 
When I do the same thing without the -p sh argument - that is just 
IPShellEmbed() - it works.

Second, I tried to pass a command in the form "var=!echo hi" to 
ipshell.IP.runlines. This works when running the script directly from 
the command line with "python script.py", but _not_ when called in a 
separate IPython instance via "run script.py". In the latter case I get 
a "SyntaxError: invalid syntax" exception. It also doesn't work when the 
code is included from another module (I have absolutely no idea why). I 
guess the error has something to do with the exclamation mark getting 
not escaped but I don't know why this is so only when running from "run" 
in IPython and another module.

Is the runlines() method the right way to execute a string inside a 
python script?

Any Ideas?


More information about the IPython-User mailing list