Issue
Suppose that I start IPython with the following command in the Windows 10 CMD:
"C:\MyFolder\ipython.exe" -i --matplotlib=qt5 --InteractiveShellApp.exec_lines="['import numpy as np']"
From within the IPython console that is initialized, is there a way for me to find exactly which command was used to initialize the IPython console (which is the above)?
If not, is there at least a way to retrieve the part "C:\MyFolder\ipython.exe"
, that is the exact path to the currently run ipython file?
Solution
The information you're requesting (raw program arguments as passed - say - to a C program with main(int argc, char *argv)
) is not available at the python interpreter level (a more complete - but partial because it doesn't address python command and switches - explanation is provided in How do I find the exact CLI command given to Python?)
sys.argv
provides the arguments that you're passing to your script, including the script itself as sys.argv[0]
, but not the python command line switches.
One thing you can get, though, is the executable which was launched: sys.executable
So the closest you can do is:
args = [sys.executable] + sys.argv
Answered By - Jean-François Fabre
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.