Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running from shell and iPython

Not sure how to go about an issue I have. I execute my code in through command line in format:

python program.py arg1 arg2

Which is fine in most cases, but I just got iPython and I want to launch the code in iPython to use it for debugging. However, I cant find the best way to pass arguments.

executable('program') isn't sufficient for this

and kind of having trouble with subprocess, cant make it work

subprocess.call([sys.executable, 'program.py','arg1'])
like image 813
rodling Avatar asked Jan 28 '26 09:01

rodling


1 Answers

You should be able to just run ipython program.py arg1 arg2. If you then want to interact with the program after the script runs, do ipython -i program.py arg1 arg2. The -i flag works the same for ipython as it does for python.

If you are already inside ipython and want to run your script, you can use the ipython magic function to run a script with run program.py arg1 arg2. You also use the -m option with the run function, and it will work similar to the -m option on regular python to run a module by name rather than a script path.

like image 109
jlund3 Avatar answered Jan 30 '26 04:01

jlund3