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 614 views
3 answers 589 views
1 answer 286 views
1 answer 281 views
1 answer 272 views
1 answer 346 views
...