2014-07-06 37 views
3

我一直在尋找一個回購和後一個逗號跨越有點怪異線導入與爲

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

是什麼意思導入這樣來的?我以前沒有見過,不幸的是,它很難谷歌。

回答

6

這行告訴Python來導入TestCaseTwill從包裝flask.ext.testing,但Base名義進口TestCase

docs

如果模塊名稱後面as,然後以下as名稱是 直接結合到導入的模塊。

下面是與searchmatch功能的演示從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 
>>> 
+0

沒關係啊。這句法似乎很尷尬imo – corvid