Gabriel Gabriel - 5 months ago 23
Python Question

sys.argv[0] is not showing the name of file in python

If I understand correctly, When typing sys.argv[0] it shows the name of the .py file one is working on. But when I do this, it shows me a different name:

sys.argv[0]
'C:\\Anaconda\\lib\\site-packages\\spyderlib\\widgets\\externalshell\\start_ipython_kernel.py'


The real name of the file is 'Ra x 13 arima.py' and its located in 'C:\Users\infantjo\Documents\Python Scripts\Projects\Work in Progress'

The current directory is:

os.getcwd()
'C:\\Users\\infantjo\\Documents\\Python Scripts\\Projects'


What am I doing wrong?

(Im using Python 2.7.11 in Spyder 2.3.8 installed with Anaconda 2.3.0, 64bit).

Answer

argv contain a list of command line arguments passed to python script. argv[0] is the script name. doc

IDE like Spyder / PyCharm doesn't run the script direct. It's run the wrapper that run Your script.

In this case Spyder run the start_ipython_kernel.py script that get a Your script name as a parameter and run it.

If You need a script name use a __file__ var.

Comments