What is the PEP8 recommendation for multiple imports from a package?

旧街凉风 提交于 2020-06-15 06:23:11

问题


The PEP8 style guide section on imports seems to be a bit ambiguous.

From: https://www.python.org/dev/peps/pep-0008/#imports

The first part makes sense:

# Imports should usually be on separate lines:

# Correct:
import os
import sys

# Wrong:
import sys, os

But then it goes on to say:

# It's okay to say this though:

# Correct:
from subprocess import Popen, PIPE

How should we interpret this? subprocess is a module, so is PEP8 saying it's just OK to import multiple things from a single module on one line? Or is it saying it's OK to import any number of things from a higher level entity on one line? I.e. is importing multiple modules from a package good style?

I'm sure arguments could be made for either style, so I'm not asking for opinions on that, but is there an authoritative source on what the PEP8 intent is here?

来源:https://stackoverflow.com/questions/62087225/what-is-the-pep8-recommendation-for-multiple-imports-from-a-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!