当前位置: 首页>>代码示例>>Python>>正文


Python operator.__lt__方法代码示例

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


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

示例1: __init__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def __init__(self, attribute, value=None, op=None, probability=1, **kwargs):
        super(self.__class__, self).__init__(kwargs)
        self.__available_operators = {"==": operator.__eq__, "<": operator.__lt__,
                                      ">": 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,代码来源:NodeNumericalAttribute.py

示例2: lrange

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def lrange(num1, num2=None, step=1):
    """
    Allows iteration over arbitrary numbers instead of dword long numbers.
    Credits go to:
    http://stackoverflow.com/questions/2187135/range-and-xrange-for-13-digit-numbers-in-python
    http://stackoverflow.com/users/263162/ricardo-cardenes
    """
    op = operator.__lt__

    if num2 is None:
        num1, num2 = 0, num1
    if num2 < num1:
        if step > 0:
            num1 = num2
        op = operator.__gt__
    elif step < 0:
        num1 = num2

    while op(num1, num2):
        yield num1
        num1 += step 
开发者ID:danielplohmann,项目名称:apiscout,代码行数:23,代码来源:IdaTools.py

示例3: assert_array_less

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def assert_array_less(x, y, err_msg='', verbose=True):
    """
    Checks that x is smaller than y elementwise.

    """
    assert_array_compare(operator.__lt__, x, y,
                         err_msg=err_msg, verbose=verbose,
                         header='Arrays are not less-ordered') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:testutils.py

示例4: __lt__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def __lt__(self, other):
        return self.__comparator__(other, operator.__lt__) 
开发者ID:google,项目名称:rekall,代码行数:4,代码来源:obj.py

示例5: __lt__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def __lt__(self, other):
        return self.x < other 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_richcmp.py

示例6: test_misbehavin

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [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<b, 0)
        self.assertEqual(a==b, 0)
        self.assertEqual(a>b, 0)
        self.assertRaises(RuntimeError, cmp, a, b) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_richcmp.py

示例7: test_goodentry

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def test_goodentry(self):
        # This test exercises the final call to PyObject_RichCompare()
        # in Objects/listobject.c::list_richcompare()
        class Good:
            def __lt__(self, other):
                return True

        x = [Good()]
        y = [Good()]

        for op in opmap["lt"]:
            self.assertIs(op(x, y), True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_richcmp.py

示例8: assert_array_less

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def assert_array_less(x, y, err_msg='', verbose=True):
    "Checks that x is smaller than y elementwise."
    assert_array_compare(operator.__lt__, x, y,
                         err_msg=err_msg, verbose=verbose,
                         header='Arrays are not less-ordered') 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:testutils.py

示例9: __lt__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def __lt__(self, other):
        return self._compare(other, operator.__lt__) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:4,代码来源:models.py

示例10: __init__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lt__ [as 别名]
def __init__(self, attribute, value=None, op=None, triggering_status=None, probability=1, **kwargs):
        super(self.__class__, self).__init__(kwargs)
        self.__available_operators = {"==": operator.__eq__, "<": operator.__lt__,
                                      ">": operator.__gt__, "<=": operator.__le__,
                                      ">=": operator.__ge__, "!=": operator.__ne__,
                                      "IN": (operator.__ge__, operator.__le__)}

        self.attribute = attribute
        self.trigger = triggering_status
        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,代码行数:28,代码来源:EdgeNumericalAttribute.py


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