我有一个模块导入了一些我想覆盖的库。例如:覆盖Python库依赖关系
module.py
import md5
def test():
print(md5.new("LOL").hexdigest())
newfile.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
我想避免/* *跳过进口,而不是执行它然后做一个替代。固定
编辑2
代码(这仅仅是一个例子)。
不,这不是一个重复:我要避免进口,不做替代。 –
另一个downvote?我会尝试更好地解释它:我不想尝试导入库,我想让“导入”无害! :D –
明白了..删除了评论。我不是downvoter :) – karthikr