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 489 views
3 answers 449 views
1 answer 209 views
1 answer 177 views
1 answer 191 views
1 answer 234 views
...