我有一个模块可以导入一些我想覆盖的库。例子:
模块.py
import md5
def test():
print(md5.new("LOL").hexdigest())
新文件.py
class fake:
def __init__(self, text):
self.text = text
def hexdigest(self):
return self.text
import sys
module = sys.argv[1] # It contains "module.py"
# I need some magic code to use my class and not the new libraries!
__import__(module)
编辑 1
我想避免/*skip* 导入,而不是执行它然后进行替换。
编辑 2
代码已修复(这只是一个示例)。