0

Hello stackoverflow community,

How can I get the script name when using execfile() in IPython to run the script?

Demonstration:

I've created this script (named printScriptName.py)

import os,sys
print os.path.basename(sys.argv[0])

This is the output when running it using IPython:

In [37]: execfile('printScriptName.py')
ipython-script.py

Which is obviously not printScriptName.py.

Thanks.

Cilyan
  • 7,883
  • 1
  • 29
  • 37
golosovsky
  • 638
  • 1
  • 6
  • 19
  • @Cilyan the asnwers on the mentioned thread return ipython-script.py in my case -- which is not the desired output. – golosovsky Feb 07 '16 at 15:35
  • 1
    Indeed. See here then: https://stackoverflow.com/questions/50499/how-do-i-get-the-path-and-name-of-the-file-that-is-currently-executing – Cilyan Feb 07 '16 at 15:42

0 Answers0