[英]Import Error: Cannot import function after clearly declaring in the __init__.py
Say, I have three files __init__.py
, time.py
and readers.py
in a directory analogpy .比如说,我在一个目录analogpy中有三个文件__init__.py
、 time.py
和readers.py
。
time.py
has a class and readers.py
has function read_file()
time.py
有一个 class 和readers.py
有 function read_file()
__init__.py
has following __init__.py
有以下内容
from analogpy import time
from analogpy import readers
when I import readers from analogpy and call the function read_file() , it shows the following error当我从analogpy导入阅读器并调用 function read_file()时,它显示以下错误
from analogpy import readers
ImportError: cannot import name 'read_file' from 'analogpy' (analogpy/__init__.py)
Functions are clearly defined because I see they work fine when compiling individual files.函数定义明确,因为我发现它们在编译单个文件时工作正常。 What am I not understanding here?我在这里不明白什么?
__init__.py
like this:你可以像这样更新你的__init__.py
:from .readers import read_file
then you can from analogpy import readfile in other file and call the function然后您可以从analogpy导入其他文件中的readfile并调用function
from analogpy import readers
readers.read_file()
to call the function致电 function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.