Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6161669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:31:03+00:00 2026-05-23T21:31:03+00:00

I am trying to follow the examples from the documentation on building custom comparators

  • 0

I am trying to follow the examples from the documentation on building custom comparators using hybrid value objects,

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"

I don’t understand, however, why this was added to the end of the class definition:

key = 'word'
"Label to apply to Query tuple results"

What is this for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:31:04+00:00Added an answer on May 23, 2026 at 9:31 pm

    While it’s not a fully baked Python feature, a convention is to comment attributes in the same way as functions and methods, i.e. by placing a string below the attribute. Comments like the above are picked up by tools like Sphinx. You can see examples of these docstrings getting generated in places like http://www.sqlalchemy.org/docs/orm/mapper_config.html#sqlalchemy.orm.mapper.Mapper.class_manager.

    edit: oh why it has an actual “.key”. When you say:

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

    the “word” and “someotherword” tuple keys are the value of “.key” on each comparator. if you were to call label() on it, that would change it to something else. I don’t know that it’s strictly necessary to be there at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to follow the examples from here http://www.haskell.org/cabal/users-guide/#test-suites When I run cabal
I have been trying to follow this example from propel to configure a custom
I am trying to follow this example (from p137 of Rob Pickering's Foundations of
I'm trying follow a tutorial to create a custom USB driver in Linux and
We are trying to follow the branching strategy from the TFS Branching Guide and
I am trying to follow this example from MSDN: http://msdn.microsoft.com/en-us/library/a1hetckb.aspx I think i'm doing
I have been trying to follow this example (download the source code from a
I am trying to follow examples given in various places for D apps. Generally
I'm trying to follow this simple examples given in the google web store API
I'm trying to figure out how to launch a Service from a singleton class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.