Answers for "python name of current file"

3

python name of current file

from pathlib import Path
print(Path(__file__).stem) #myfile
print(Path(__file__).name) #myfile.py
Posted by: Guest on April-23-2021
1

get self file name in python

import os

os.path.basename(__file__)
Posted by: Guest on May-26-2020
0

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__)
Posted by: Guest on February-25-2020

Code answers related to "python name of current file"

Python Answers by Framework

Browse Popular Code Answers by Language