gpt4 book ai didi

python - 在 as 之后用逗号导入

转载 作者:太空宇宙 更新时间:2023-11-03 13:43:48 27 4
gpt4 key购买 nike

我正在查看一个 repo,发现了一条有点奇怪的线

from flask.ext.testing import TestCase as Base, Twill

这样导入是什么意思?我以前没见过它,不幸的是很难用谷歌搜索。

最佳答案

该行告诉 Python 从包 flask.ext.testing 中导入 TestCaseTwill,但是要导入 TestCaseBase 的名称下。

来自docs :

If the module name is followed by as, then the name following as is bound directly to the imported module.

下面是来自re modulesearchmatch 函数的演示。 :

>>> from re import search as other, match
>>> match # The name match refers to re.match
<function match at 0x02039780>
>>> other # The name other refers to re.search
<function search at 0x02048A98>
>>> search # The name search is not defined because it was imported as other
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'search' is not defined
>>>

关于python - 在 as 之后用逗号导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24601422/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com