How to Get Name of Current Script in Python
Using Module Attributes
You can use __file__ to get the name of the current file. When used in the main module, this is the name of the script that was originally invoked.
See the following example:
#!/usr/bin/python3 # Import module import os print(__file__) # omit the directory part print(os.path.basename(__file__))