如何在python的一行中放置多个导入 [英] How to place multiple imports in a single line in python

查看:96
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆