Enumeration idioms: Values from different enumerations
bignose+hates-spam at benfinney.id.au
Mon Dec 19 23:16:03 CET 2005
eswald at gmail.com writes:
> Ben Finney wrote:
>> Is there some behaviour other than "evaluate to False" or "raise an
>> exception", that could indicate "not comparable"?
> Yes: return NotImplemented. Note that the == operator automagically
> returns False in this case.
> >>> "spam".__eq__("spam")
> >>> "spam".__eq__("ham")
> >>> "spam".__eq__(23)
> This way, the user could explicitly call __eq__ and check for
> NotImplemented if he desires the exceptional behavior.
Thanks, I was unaware of the standard usage of NotImplemented. That
seems like a sensible solution.
\ "My doctor told me to stop having intimate dinners for four. |
`\ Unless there are three other people." -- Orson Welles |
More information about the Python-list