How to modify imported source code on-the-fly?

前端 未结 5 1945
悲哀的现实
悲哀的现实 2020-12-09 17:32

Suppose I have a module file like this:

# my_module.py
print(\"hello\")

Then I have a simple script:

# my_script.py
import          


        
5条回答
  •  忘掉有多难
    2020-12-09 18:31

    Not elegant, but works for me (may have to add a path):

    with open ('my_module.py') as aFile:
        exec (aFile.read () .replace (, ))
    

提交回复
热议问题