Issue
The python script I would use (source code here) would parse some arguments when called from the command line. However, I have no access to the Windows command prompt (cmd.exe) in my environment. Can I call the same script from within a Python console? I would rather not rewrite the script itself.
Solution
%run
is a magic in IPython that runs a named file inside IPython as a program almost exactly like running that file from the shell. Quoting from %run?
referring to %run file args
:
This is similar to running at a system prompt python file args
,
but with the advantage of giving you IPython's tracebacks, and of
loading all variables into your interactive namespace for further use
(unless -p is used, see below). (end quote)
The only downside is that the file to be run must be in the current working directory or somewhere along the PYTHONPATH
. %run
won't search $PATH
.
%run
takes several options which you can learn about from %run?
. For instance: -p
to run under the profiler.
Answered By - Wolf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.