我有一個模塊導入了一些我想覆蓋的庫。例如:覆蓋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