This attribute with the os module could be used to get the name of the currently running Python script. Here's how you can do this:
import os
script_name = os.path.basename(__file__)
print(script_name)
Explanation:
__file__ is a special variable holding the path to the script being executed. The function os.path.basename extracts just the filename from that path. If you run this code in a script like foo.py, the output will always be foo.py, regardless of where it was sourced or launched from.
This is really useful when you want the name of the script for logging purposes but don't have it available while the script is actually running