python get current file name code example
Example 1: python get current file location
import os
os.path.dirname(os.path.abspath(__file__))
Example 2: python get script name
from pathlib import Path
Path(__file__).name
Path(__file__).stem
import os
os.path.basename(__file__)
os.path.splitext(os.path.basename(__file__))[0]
Example 3: python name of current file
from pathlib import Path
print(Path(__file__).stem)
print(Path(__file__).name)
Example 4: get self file name in python
import os
os.path.basename(__file__)