[Python-Dev] Getting values stored inside sets (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Sat Apr 4 03:54:51 CEST 2009


Paul Moore wrote:

2009/4/3 R. David Murray <rdmurray at bitdance.com>:

a == b

So, python calls a.eq(b) Now, that function does: a.key == b Since b is an object with an eq method, python calls b.eq(a.key). That's the bit I can't actually find documented anywhere.

It doesn't quite work the way RDM desribed it - he missed a step.

a == b

So, python calls a.eq(b)

Now, that function does:

a.key == b

which first calls a.key.eq(b) # This step was missing

Since str has no idea what an Element is, that returns NotImplemented.

Since eq is defined as being commutative, the interpreter then tries b.eq(a.key).

That function does:

b.key == a.key

which calls b.key.eq(a.key)

which is a well defined string comparison and returns the expected answer.

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list