3
我試圖按照從文檔的例子中使用混合值對象建立custom comparators,SQLAlchemy的:混合值對象,查詢結果的元組
class CaseInsensitiveWord(Comparator):
"Hybrid value representing a lower case representation of a word."
def __init__(self, word):
if isinstance(word, basestring):
self.word = word.lower()
elif isinstance(word, CaseInsensitiveWord):
self.word = word.word
else:
self.word = func.lower(word)
def operate(self, op, other):
if not isinstance(other, CaseInsensitiveWord):
other = CaseInsensitiveWord(other)
return op(self.word, other.word)
def __clause_element__(self):
return self.word
def __str__(self):
return self.word
key = 'word'
"Label to apply to Query tuple results"
我不明白,但是,爲什麼這個加入類定義的末尾:
key = 'word'
"Label to apply to Query tuple results"
這是幹什麼用的?
謝謝,但我也很好奇,屬性本身有什麼意義?鍵? – john