Answers for "get file name of current python script"

3

get current file name python

import os
os.path.basename(__file__)
Posted by: Guest on July-18-2021
2

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 name of a file in python

>>> f = open('/tmp/generic.png','r')
>>> f.name
'/tmp/generic.png'
>>> import os
>>> os.path.basename(f.name)
'generic.png'
Posted by: Guest on May-24-2020

Code answers related to "get file name of current python script"

Python Answers by Framework

Browse Popular Code Answers by Language