如何在python的一行中放置多个导入 [英] How to place multiple imports in a single line in python
问题描述
我的问题是关于如何在一行中放置多个导入.
My question is about how to place multiple imports in a single line.
from sys import argv
from os.path import exists
我们能否将上述语句修改为如下所示的单个语句:
Can we modify the above statements into a single statement like the one shown below:
from sys,os.path import argv,exists
我们可以那样做吗..?如果我错了,请纠正我.
Can we do it that way..?Please do correct me if I am wrong.
推荐答案
不,你不能.对不起!
python import
语句仅支持一个模块一次导入语句.
The python import
statement only supports one module to import statements from at a time.
如果你可以这样做,假设来说,以下意味着什么:
If you could do this, hypothetically speaking, what would the following mean:
from threading, multiprocessing import Thread, Condition, Lock
Condition
将从哪个模块导入?两个模块都定义了这样一个类.
what module would Condition
be imported from? Both modules define such a class.
Python 更喜欢显式而不是隐式;您一次选择一个要从中导入的来源,因为这会导致最不意外和最清楚发生的事情.
Python prefers explicit over implicit; you select one source from which to import at a time as that results in the least surprise and the greatest clarity as to what is happening.
这篇关于如何在python的一行中放置多个导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!