【发布时间】:2018-09-14 14:55:31
【问题描述】:
我有一个模块(比如模块 A),它的一个功能返回一个 BeautifulSoup 对象。我正在编写第二个模块(模块 B),它调用此函数并存储该 BeautifulSoup 对象。我很困惑如何在模块 B 中的模块 A 返回的对象上调用 BeautifulSoup 函数,而无需模块 B 从 bs4 导入任何内容,或者必须通过模块 A 访问这些 BS4 函数。导入基本上是把 module_a 及其所有在包中导入,所以 BeautifulSoup 类对 module_b 是可见的?
module_a.py
from bs4 import BeautifulSoup
def function():
some_xml = "<name>Namespaces are strange.</name>"
return BeautifulSoup(some_xml, "xml")
module_b.py
import module_a
def main():
# How does this line know what to do with .find()? or .string?
print(module_a.function().find("name").string)
【问题讨论】:
标签: python python-3.x import beautifulsoup python-module