python name of current file code example
Example 1: python name of current file
from pathlib import Path
print(Path(__file__).stem) #myfile
print(Path(__file__).name) #myfile.py
Example 2: get self file name in python
import os
os.path.basename(__file__)
Example 3: get the name of a current script in python
Use __file__. If you want to omit the directory part (which might be present), you can use os.path.basename(__file__)