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 469 views
3 answers 423 views
1 answer 198 views
1 answer 164 views
1 answer 176 views
1 answer 223 views
...