[英]How can I import the function?
I have a Python function in a file called func.py
我在一个名为
func.py
的文件中有一个Python函数
def calc(x,y):
return x*y
I have to import this function while working in another file called mytask.py 我必须在另一个名为mytask.py的文件中导入此函数
How can I import the function? 我该如何导入该功能?
Save the file in the same directory and then have a statement 将文件保存在同一目录中,然后生成一个语句
from func import calc
To import from a different directory 从其他目录导入
__init__.py
and have a line __all__ = ['calc']
__init__.py
并有一行__all__ = ['calc']
from funcs import func
from funcs import func
Reference 参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.