【发布时间】:2022-01-19 20:11:16
【问题描述】:
我有以下问题:
假设我有一个文件function.py,其中包含:
def get_mean(nums):
return np.mean([nums])
以及包含以下内容的文件launcher.py:
from function import get_mean
mean = get_mean([1, 2, 3])
print(mean)
现在,如果您启动 python launcher.py,它将抛出 NameError: name 'np' is not defined。
我的问题是:有没有办法通过从launcher.py 调用函数get_mean 使其工作,而无需编辑文件function.py?
背景故事:第三方库在此处有一个由function.py 表示的函数,但导入错误,我必须在launcher.py 表示的代码中使用该函数,我不知道该怎么做.
【问题讨论】:
标签: python module namespaces