當前位置: 首頁>>代碼示例>>Python>>正文


Python operator.truth方法代碼示例

本文整理匯總了Python中operator.truth方法的典型用法代碼示例。如果您正苦於以下問題:Python operator.truth方法的具體用法?Python operator.truth怎麽用?Python operator.truth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在operator的用法示例。


在下文中一共展示了operator.truth方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_operator

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        with test_support.check_py3k_warnings():
            self.assertIs(operator.isCallable(0), False)
            self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_bool.py

示例2: boolean

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def boolean(value, _truefalse=(False, True)):
        """Convert any Python value to XML-RPC 'boolean'."""
        return _truefalse[operator.truth(value)]

##
# Wrapper for XML-RPC DateTime values.  This converts a time value to
# the format used by XML-RPC.
# <p>
# The value can be given as a string in the format
# "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
# time.localtime()), or an integer value (as returned by time.time()).
# The wrapper uses time.localtime() to convert an integer to a time
# tuple.
#
# @param value The time, given as an ISO 8601 string, a time
#              tuple, or a integer time value. 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:18,代碼來源:_pydev_xmlrpclib.py

示例3: test_operator

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        self.assertIs(operator.isCallable(0), False)
        self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:24,代碼來源:test_bool.py

示例4: __init__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def __init__(self, value = 0):
            self.value = operator.truth(value) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:4,代碼來源:xmlrpclib.py

示例5: boolean

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def boolean(value, _truefalse=(False, True)):
        """Convert any Python value to XML-RPC 'boolean'."""
        return _truefalse[operator.truth(value)] 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:5,代碼來源:xmlrpclib.py

示例6: test_bool_values

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def test_bool_values(self):
        from operator import truth
        for t, v in zip(bool_types, bool_values):
            self.assertEqual(t(v).value, truth(v)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_numbers.py

示例7: test_truth

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def test_truth(self):
        class C(object):
            def __nonzero__(self):
                raise SyntaxError
        self.assertRaises(TypeError, operator.truth)
        self.assertRaises(SyntaxError, operator.truth, C())
        self.assertTrue(operator.truth(5))
        self.assertTrue(operator.truth([0]))
        self.assertFalse(operator.truth(0))
        self.assertFalse(operator.truth([])) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_operator.py

示例8: parse_stdout_filelist

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def parse_stdout_filelist(hg_out_filelist):
    files = hg_out_filelist.split()
    files = [f.strip(string.whitespace + "'") for f in files]
    files = list(filter(operator.truth, files))  # get rid of empty entries
    return files 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:7,代碼來源:check_whitespace.py

示例9: __init__

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def __init__(self, value=0):
            self.value = operator.truth(value) 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:4,代碼來源:_pydev_xmlrpclib.py

示例10: getBroadcastAllowed

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def getBroadcastAllowed(self):
        """
        Checks if broadcast is currently allowed on this port.

        @return: Whether this port may broadcast.
        @rtype: L{bool}
        """
        return operator.truth(
            self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:udp.py

示例11: setLoopbackMode

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def setLoopbackMode(self, mode):
        mode = struct.pack("b", operator.truth(mode))
        self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_LOOP,
                               mode) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:6,代碼來源:udp.py

示例12: getTcpNoDelay

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def getTcpNoDelay(self):
        return operator.truth(self.socket.getsockopt(socket.IPPROTO_TCP,
                                                     socket.TCP_NODELAY)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:5,代碼來源:tcp.py

示例13: getTcpKeepAlive

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def getTcpKeepAlive(self):
        return operator.truth(self.socket.getsockopt(socket.SOL_SOCKET,
                                                     socket.SO_KEEPALIVE)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:5,代碼來源:tcp.py

示例14: getTcpNoDelay

# 需要導入模塊: import operator [as 別名]
# 或者: from operator import truth [as 別名]
def getTcpNoDelay(self):
        return operator.truth(self.socket.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:4,代碼來源:tcp.py


注:本文中的operator.truth方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。