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

Related questions

1 answer 121 views
1 answer 198 views
3 answers 423 views
2 answers 183 views
1 answer 103 views
...