在Python中导入一个模块后,如何在同一工作空间中撤销其影响?
例如,在Python IDLE中输入“import random”后,我想在同一工作空间中删除模块“random”中导入的所有函数,我该怎么做?
在Python中导入一个模块后,如何在同一工作空间中撤销其影响?
例如,在Python IDLE中输入“import random”后,我想在同一工作空间中删除模块“random”中导入的所有函数,我该怎么做?
def do_something_with_random():
import random
print("do something interesting with random", random.choice([0, 1]))
print("perform task that don't need random")
do_something_with_random()
print("function call uses random, but doesn't add it to your globals")
print("continue performing tasks that don't need random")