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 133 views
1 answer 210 views
3 answers 450 views
2 answers 203 views
1 answer 118 views
...