【发布时间】:2021-05-26 05:51:42
【问题描述】:
什么是导入模块的“好习惯”?例如,如果我有一个名为“module”的模块和一个名为“func”的函数,哪个更好?
1:
def do_things():
from module import func
func()
2:
from module import func
def do_things():
func()
3:
import module as mod
def do_things():
mod.func()
4:
def do_things():
import module as mod
mod.func()
我需要确保我的代码为这个项目编写得很好。同样从模块中导入类(例如“from bs4 import BeautifulSoup”)是否可以将它们导入我程序顶部的全局命名空间?如果不是,是否适用与此处相同的规则?
【问题讨论】:
标签: python class oop import module