python - SQLAlchemy: Hybrid Value Object, Query Tuple Results -


i trying follow examples documentation on building custom comparators using hybrid value objects,

class caseinsensitiveword(comparator):     "hybrid value representing lower case representation of 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 apply query tuple results" 

i don't understand, however, why added end of class definition:

key = 'word' "label apply query tuple results" 

what for?

while it's not baked python feature, convention comment attributes in same way functions , methods, i.e. placing string below attribute. comments above picked tools sphinx. can see examples of these docstrings getting generated in places http://www.sqlalchemy.org/docs/orm/mapper_config.html#sqlalchemy.orm.mapper.mapper.class_manager.

edit: oh why has actual ".key". when say:

for row in session.query(myclass.mycustomthing, myclass.myothercustomthing):    print row.word, row.someotherword 

the "word" , "someotherword" tuple keys value of ".key" on each comparator. if call label() on it, change else. don't know it's strictly necessary there @ all.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -