import os os.path.basename(__file__)
from pathlib import Path print(Path(__file__).stem) #myfile print(Path(__file__).name) #myfile.py