我在同一个目录中有一个名为AsyncDownloaderTest且main.py
和AsyncDownloader.py
的项目。我刚刚开始学习python,但似乎问题在于导入。
main.py
from .AsyncDownloader import AsyncDownloader
ad = AsyncDownloader()
ad.setSourceCSV("https://people.sc.fsu.edu/~jburkardt/data/csv/grades.csv","First name")
print(ad.printURLs)
AsyncDownloader.py
import pandas as pd
class AsyncDownloader:
"""Download files asynchronously"""
__urls = None
def setSourceCSV(self, source_path, column_name):
self.source_path = source_path
self.column_name = column_name
# TODO Check if path is a valid csv
# TODO Store the urls found in column in a list
my_csv = pd.read_csv(source_path, usecols=[column_name], chunksize=10)
for chunk in my_csv:
AsyncDownloader.urls += chunk.column_name
def printURLs(self):
print(AsyncDownloader.urls)
我收到以下错误
ModuleNotFoundError: No module named '__main__.AsyncDownloader'; '__main__' is not a package
答案 0 :(得分:2)
您是否__init__.py
与AsyncDownloader.py
在同一目录中?应该这样做。
__init__.py
是一个空文件,表示该目录包含包,并使该目录中的.py
个文件可以导入函数和类。
您也可能会失去.
中的领先from .AsyncDownloader
。如果您愿意,可以通过将导入更改为绝对导入:
from enclosing_folder.AsyncDownloader import AsyncDownloader