![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.python archiveRe: __eq__ on a dict
From: Steven D'Aprano <steve@REMOVETHIScyber.com.au>
Date: Mon Jul 11 2005 - 13:48:11 CEST
On Mon, 11 Jul 2005 12:42:55 +0200, Neil Benn wrote:
> Hello,
It works for me. Google on "__eq__ Python" and the 5th and 6th sites are:
http://python.active-venture.com/ref/customization.html
Normally, asking Python for help is a good way to read the docs, but in
py> help({}.__eq__)
For any two objects x and y, when you call
x == y
Python calls x.__eq__(y). That includes dicts:
py> dictA = {0: "spam"}
Two dicts are equal if they have the same keys and the same values.
In general, you should not call __eq__ directly, but use the == operator
Likewise:
x > y becomes x.__gt__(y)
-- StevenReceived on Thu Sep 29 16:52:34 2005 |