[IPython-user] IPython.ipapi.launch_new_instance tries to execute all files in sys.argv!
Matthew Wilson
matt@tplus1....
Wed Jul 22 21:57:51 CDT 2009
I have a script that takes an optional argument of a data file at the
When I provide the data file, IPython tries to execute that file. Here's an
example:
$ cat bug.py
import IPython.ipapi
IPython.ipapi.launch_new_instance()
Without any arguments to bug.py, everything is fine:
$ python bug.py
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
Type "copyright", "credits" or "license" for more information.
IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]:
But when I give an argument of a file to bug.py, I get this error:
$ python bug.py ~/.vimrc
------------------------------------------------------------
File "/home/matt/.vimrc", line 1
"This is a homemade file that probably needs to be organized better.
^
SyntaxError: EOL while scanning string literal
WARNING: Failure executing file: </home/matt/.vimrc> (c)
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
Type "copyright", "credits" or "license" for more information.
IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]:
However, when I add on an argument that is NOT a file, I don't get an error:
$ python bug.py 123
Could not open file <123> for safe execution.
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
Type "copyright", "credits" or "license" for more information.
IPython 0.9.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]:
Instead, I get the message that IPython couldn't safely execute my file, which
is still bad.
I found this code in line 90 of ipmaker.py that seems to be relevant:
if argv is None:
argv = sys.argv
A few questions:
1. Is IPython.ipapi.launch_new_instance the right way to start an IPython
session?
2. Is this a bug?
IPython is great.
Matt
More information about the IPython-user
mailing list