How to get the current script (code) file name in Python

2 Answers

0 votes
import sys

print(sys.argv[0])


'''
run:

C:/Users/.../python/test/test.py

'''

 



answered Mar 9, 2018 by avibootz
0 votes
import os

print(os.path.basename(__file__))


'''
run:

test.py

'''

 



answered Mar 9, 2018 by avibootz
...