cor*_*vid 3 python syntax import
我正在看一个回购,并遇到了一个有点奇怪的线
from flask.ext.testing import TestCase as Base, Twill
Run Code Online (Sandbox Code Playgroud)
这样导入是什么意思?我以前没见过它,不幸的是谷歌很难.
该行告诉Python导入TestCase
和Twill
从包flask.ext.testing
中导入,但要TestCase
以名称导入Base
.
来自文档:
如果后跟模块名称
as
,则以下名称as
将直接绑定到导入的模块.
下面是与示范search
,并match
从功能re
模块:
>>> 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
>>>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
294 次 |
最近记录: |