python operator.eq_Python operator.__eq__方法代码示例

本文整理汇总了Python中operator.__eq__方法的典型用法代码示例。如果您正苦于以下问题:Python operator.__eq__方法的具体用法?Python operator.__eq__怎么用?Python operator.__eq__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块operator的用法示例。

在下文中一共展示了operator.__eq__方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_dicts

​点赞 6

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def test_dicts(self):

# Verify that __eq__ and __ne__ work for dicts even if the keys and

# values don't support anything other than __eq__ and __ne__ (and

# __hash__). Complex numbers are a fine example of that.

import random

imag1a = {}

for i in range(50):

imag1a[random.randrange(100)*1j] = random.randrange(100)*1j

items = imag1a.items()

random.shuffle(items)

imag1b = {}

for k, v in items:

imag1b[k] = v

imag2 = imag1b.copy()

imag2[k] = v + 1.0

self.assertTrue(imag1a == imag1a)

self.assertTrue(imag1a == imag1b)

self.assertTrue(imag2 == imag2)

self.assertTrue(imag1a != imag2)

for opname in ("lt", "le", "gt", "ge"):

for op in opmap[opname]:

self.assertRaises(TypeError, op, imag1a, imag2)

开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,

示例2: __init__

​点赞 6

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def __init__(self, attribute, value=None, op=None, probability=1, **kwargs):

super(self.__class__, self).__init__(kwargs)

self.__available_operators = {"==": operator.__eq__, "

">": operator.__gt__, "<=": operator.__le__,

">=": operator.__ge__, "!=": operator.__ne__,

"IN": (operator.__ge__, operator.__le__)}

self.attribute = attribute

self.attribute_range = value

self.probability = probability

self.operator = op

if self.attribute_range is None:

raise ValueError("A valid attribute value must be provided")

if self.operator is not None and self.operator in self.__available_operators:

if self.operator == "IN":

if not isinstance(self.attribute_range, list) or self.attribute_range[1] < self.attribute_range[0]:

raise ValueError("A range list is required to test IN condition")

else:

if not isinstance(self.attribute_range, int):

if not isinstance(self.attribute_range, float):

raise ValueError("A numeric value is required to test the selected condition")

else:

raise ValueError("The operator provided '%s' is not valid" % operator)

开发者ID:GiulioRossetti,项目名称:ndlib,代码行数:27,

示例3: test_dicts

​点赞 6

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def test_dicts(self):

# Verify that __eq__ and __ne__ work for dicts even if the keys and

# values don't support anything other than __eq__ and __ne__ (and

# __hash__). Complex numbers are a fine example of that.

import random

imag1a = {}

for i in range(50):

imag1a[random.randrange(100)*1j] = random.randrange(100)*1j

items = list(imag1a.items())

random.shuffle(items)

imag1b = {}

for k, v in items:

imag1b[k] = v

imag2 = imag1b.copy()

imag2[k] = v + 1.0

self.assertEqual(imag1a, imag1a)

self.assertEqual(imag1a, imag1b)

self.assertEqual(imag2, imag2)

self.assertTrue(imag1a != imag2)

for opname in ("lt", "le", "gt", "ge"):

for op in opmap[opname]:

self.assertRaises(TypeError, op, imag1a, imag2)

开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,

示例4: test_dicts

​点赞 6

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def test_dicts(self):

# Verify that __eq__ and __ne__ work for dicts even if the keys and

# values don't support anything other than __eq__ and __ne__ (and

# __hash__). Complex numbers are a fine example of that.

import random

imag1a = {}

for i in range(50):

imag1a[random.randrange(100)*1j] = random.randrange(100)*1j

items = imag1a.items()

random.shuffle(items)

imag1b = {}

for k, v in items:

imag1b[k] = v

imag2 = imag1b.copy()

imag2[k] = v + 1.0

self.assert_(imag1a == imag1a)

self.assert_(imag1a == imag1b)

self.assert_(imag2 == imag2)

self.assert_(imag1a != imag2)

for opname in ("lt", "le", "gt", "ge"):

for op in opmap[opname]:

self.assertRaises(TypeError, op, imag1a, imag2)

开发者ID:ofermend,项目名称:medicare-demo,代码行数:24,

示例5: assert_array_equal

​点赞 5

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def assert_array_equal(x, y, err_msg='', verbose=True):

"""

Checks the elementwise equality of two masked arrays.

"""

assert_array_compare(operator.__eq__, x, y,

err_msg=err_msg, verbose=verbose,

header='Arrays are not equal')

开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,

示例6: __eq__

​点赞 5

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def __eq__(self, other):

return other is None

开发者ID:google,项目名称:rekall,代码行数:4,

示例7: __ne__

​点赞 5

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def __ne__(self, other):

return not self == other

# We must define __hash__ in the same class as __eq__:

# https://bugs.python.org/issue2235

开发者ID:google,项目名称:rekall,代码行数:7,

示例8: __eq__

​点赞 5

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def __eq__(self, other):

return self.x == other

开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,

示例9: test_misbehavin

​点赞 5

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def test_misbehavin(self):

class Misb:

def __lt__(self_, other): return 0

def __gt__(self_, other): return 0

def __eq__(self_, other): return 0

def __le__(self_, other): self.fail("This shouldn't happen")

def __ge__(self_, other): self.fail("This shouldn't happen")

def __ne__(self_, other): self.fail("This shouldn't happen")

def __cmp__(self_, other): raise RuntimeError, "expected"

a = Misb()

b = Misb()

self.assertEqual(a

self.assertEqual(a==b, 0)

self.assertEqual(a>b, 0)

self.assertRaises(RuntimeError, cmp, a, b)

开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,

示例10: test_badentry

​点赞 5

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def test_badentry(self):

# make sure that exceptions for item comparison are properly

# propagated in list comparisons

class Exc(Exception):

pass

class Bad:

def __eq__(self, other):

raise Exc

x = [Bad()]

y = [Bad()]

for op in opmap["eq"]:

self.assertRaises(Exc, op, x, y)

开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,

示例11: assert_array_equal

​点赞 5

# 需要导入模块: import operator [as 别名]

# 或者: from operator import __eq__ [as 别名]

def assert_array_equal(x, y, err_msg='', verbose=True):

"""Checks the elementwise equality of two masked arrays."""

assert_array_compare(operator.__eq__, x, y,

err_msg=err_msg, verbose=verbose,

header='Arrays are not equal')

开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,

注:本文中的operator.__eq__方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值