__eq__在一个字典上 [英] __eq__ on a dict
问题描述
你好,
我找不到__eq__的文件在dict上我无法找到
a描述什么是eq确实(奇怪的是它确实实现了>和<
但我不知道那是做什么的)。有谁知道(明确地)
__eq __,__ gt__,__ lt__方法做什么。
顺便说一句,谷歌不是我的朋友 - 我邀请了它最后喝酒
一周它让我站起来:-)。
干杯,
Neil >
-
Neil Benn
高级自动化工程师
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
德累斯顿
德国
< br $>
电话:+49(0)351 4173 154
电子邮件:是** @ cenix-bioscience.com
Cenix网站: http ://www.cenix-bioscience.com
Hello,
I can''t find the docs for __eq__ on a dict and I can''t find
a description on what the eq does (strangely it does implement > and <
but I have no idea what that does). Does anyone know (definitively)
what the __eq__, __gt__, __lt__ methods do.
BTW, google is not my friend - I invited it out for a drink last
week and it stood me up :-).
Cheers,
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : be**@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com
推荐答案
这些方法记录在这里:
< a rel =nofollowhref =http://docs.python.org/ref/customization.htmltarget =_ blank> http://docs.python.org/ref/customization.html
These methods are documanted here:
http://docs.python.org/ref/customization.html
2005年7月11日星期一12:42:55 +0200,Neil Benn写道:
On Mon, 11 Jul 2005 12:42:55 +0200, Neil Benn wrote:
您好,
我找不到__eq__的文档,我找不到关于eq做什么的描述(奇怪的是它确实实现了>和<
但我不知道那是做什么的。有没有人知道(明确地)
__eq __,__ gt__,__ lt__方法做什么。
顺便说一下,谷歌不是我的朋友 - 我邀请它去喝一杯
一周它让我兴奋: - )。
Hello,
I can''t find the docs for __eq__ on a dict and I can''t find
a description on what the eq does (strangely it does implement > and <
but I have no idea what that does). Does anyone know (definitively)
what the __eq__, __gt__, __lt__ methods do.
BTW, google is not my friend - I invited it out for a drink last
week and it stood me up :-).
它对我有用。谷歌在__ eq__ Python上第五和第六站点是:
http://python.active-venture.com/ref/customization.html
http://www.network-theory.co.uk/docs/pylang/ref_32.html
通常情况下,向Python寻求帮助是阅读文档的好方法,但在这个特殊情况下,这是一个很大的失误:
py> ; help({} .__ eq__)
方法包装器的帮助:
__eq__ =< method-wrapper object>
对于任何两个对象x和y,当你调用
x == y
Python调用x .__ eq __(y)。这包括dicts:
py> dictA = {0:" spam"}
py> dictB = {0:" sp" +am}
py> dictC = {1:" ham"}
py>
py> dictA == dictB
True
py> dictA .__ eq __(dictB)#与dictA相同== dictB
真
py> dictB == dictC#调用dictB .__ eq __(dictC)
False
如果两个dicts具有相同的键和相同的值,则它们是相等的。 />
一般来说,你不应该直接调用__eq__,而是使用==运算符
代替。
同样:
x> y变为x .__ gt __(y)
x< y变为x .__ lt __(y)
x> = y变为x .__ ge __(y)
x< = y变为x .__ le __(y)
x!= y变为x .__ ne __(y)
x<> y也变成x .__ ne __(y)
-
史蒂文
It works for me. Google on "__eq__ Python" and the 5th and 6th sites are:
http://python.active-venture.com/ref/customization.html
http://www.network-theory.co.uk/docs/pylang/ref_32.html
Normally, asking Python for help is a good way to read the docs, but in
this particular case, it is a big let-down:
py> help({}.__eq__)
Help on method-wrapper:
__eq__ = <method-wrapper object>
For any two objects x and y, when you call
x == y
Python calls x.__eq__(y). That includes dicts:
py> dictA = {0: "spam"}
py> dictB = {0: "sp" + "am"}
py> dictC = {1: "ham"}
py>
py> dictA == dictB
True
py> dictA.__eq__(dictB) # same as dictA == dictB
True
py> dictB == dictC # calls dictB.__eq__(dictC)
False
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
instead.
Likewise:
x > y becomes x.__gt__(y)
x < y becomes x.__lt__(y)
x >= y becomes x.__ge__(y)
x <= y becomes x.__le__(y)
x != y becomes x.__ne__(y)
x <> y also becomes x.__ne__(y)
--
Steven
wi ****** @ hotmail.com 写道:
wi******@hotmail.com wrote:
这些方法是记录的在这里:
http://docs.python.org/ref/ customization.html
These methods are documanted here:
http://docs.python.org/ref/customization.html
嗯,看不到有关python dict方法实现的任何内容
__eq __,__ lt__或__gt__那里 - 一般文档,但不是特定于
这里的字典 - 至少不是我从这些文档中看到的。
Neil
-
Neil Benn
高级自动化工程师
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
德累斯顿
德国
电话:+49(0)351 4173 154
电子邮件: be ** @ cenix-bioscience.com
Cenix网站: http://www.cenix-bioscience.com
Hmm, can''t see anything about implementation of python dict methods
__eq__, __lt__ or __gt__ there - general docs but not specific to the
dict here - at least not as far as I can see from these docs.
Neil
--
Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 46
D-01307
Dresden
Germany
Tel : +49 (0)351 4173 154
e-mail : be**@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com
这篇关于__eq__在一个字典上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!