简体   繁体   English

从包导入多个模块的首选方法

[英]Preferred way to import multiple modules from package

What is the best way to import when you need several modules from a package? 当您需要包中的多个模块时,导入的最佳方法是什么?

from PySide.QtGui import QGraphicsView, QAction, QKeySequence, QMenu, QCursor, QKeyEvent

view = QGraphicsView()
...

or 要么

import PySide.QtGui

view = QtGui.QGraphicsView()
...

or even 甚至

import PySide

view = PySide.QtGui.QGraphicsView()
...

I understand that in most cases the second way has the best tradeoff between ambiguity and length in the code. 我知道在大多数情况下,第二种方式在代码中的歧义和长度之间具有最佳权衡。 But are there any other considerations like performance when importing larger packages? 但是在导入更大的包时是否有其他考虑因素如性能?

I quote from the documentation : 我引用文档

"there is nothing wrong with using from Package import specific_submodule ! In fact, this is the recommended notation unless the importing module needs to use submodules with the same name from different packages." “使用from Package import specific_submodule没有任何问题!实际上,这是推荐的表示法,除非导入模块需要使用来自不同包的同名子模块。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM