【发布时间】:2020-07-22 16:11:37
【问题描述】:
我正在用 VS Code 编写 Webscraping 应用程序。 Pytho 版本是 3.9。
我在 VS Code 中的文件夹结构
BeautifulSoup - Scraping_Quotes - locator BeautifulSoup -Scraping_Quotes - Parsers
定位器目录有一个 quote_locators.py,其中有一个名为 QuoteLocator 的类。
当我尝试在 Parsers 目录中的 quote.py 中导入此类时,如下代码所示,我收到“No Module Named locator”错误。代码复制如下。
from locator.quote_locators import QuoteLocators
class QuoteParser:
"""
Given one of the specific Quote divs, find out the data about the quote
"""
def __init__(self, parent):
self.parent = parent
def __repr__(self):
return f'<Quote> {self.content}, by {self.author}>'
@property
def content(self):
locator = QuoteLocators.CONTENT
return self.parent.select_one(locator).string
@property
def author(self):
locator = QuoteLocators.AUTHOR
return self.parent.select_one(locator).string
@property
def tags(self):
locator = QuoteLocators.TAGS
return self.parent.select_one(locator)
我的 launch.json 文件(如果相关)有:
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${fileDirname}"
}
]
相同的代码在 Pycharm 中完美运行。
即将放弃VSCode,感谢任何帮助!!!
我在 StackOverflow 中尝试了多个建议,但没有任何效果。
【问题讨论】:
标签: python class visual-studio-code module