3
我一直在尋找一個回購和後一個逗號跨越有點怪異線導入與爲
from flask.ext.testing import TestCase as Base, Twill
是什麼意思導入這樣來的?我以前沒有見過,不幸的是,它很難谷歌。
我一直在尋找一個回購和後一個逗號跨越有點怪異線導入與爲
from flask.ext.testing import TestCase as Base, Twill
是什麼意思導入這樣來的?我以前沒有見過,不幸的是,它很難谷歌。
這行告訴Python來導入TestCase
和Twill
從包裝flask.ext.testing
,但Base
名義進口TestCase
。
從docs:
如果模塊名稱後面
as
,然後以下as
名稱是 直接結合到導入的模塊。
下面是與search
和match
功能的演示從re
module:
>>> 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
>>>
沒關係啊。這句法似乎很尷尬imo – corvid