SubniC SubniC - 1 year ago 149
Python Question

Get the name of current script with Python

I'm trying to get the name of the Python script that is currently running.

For example, I have a script called
and I would like to do something like this inside it:

print Scriptname

and get:

Answer Source

Use __file__. If you want to omit the directory part (which might be present), you can use import os,os.path.basename(__file__).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download