How to get the current script code (source code) in Python

1 Answer

0 votes
import inspect
import sys

print("python 3")

print(inspect.getsource(sys.modules[__name__]))



'''
run:

python 3
import inspect
import sys

print("python 3")

print(inspect.getsource(sys.modules[__name__]))

'''

 



answered Jul 26, 2024 by avibootz
edited Jul 26, 2024 by avibootz

Related questions

2 answers 490 views
3 answers 451 views
1 answer 210 views
1 answer 177 views
1 answer 192 views
1 answer 234 views
...