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


Python c_char.from_address方法代碼示例

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


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

示例1: test_int_from_address

# 需要導入模塊: from ctypes import c_char [as 別名]
# 或者: from ctypes.c_char import from_address [as 別名]
def test_int_from_address(self):
        from array import array
        for t in signed_types + unsigned_types:
            # the array module doesn't support all format codes
            # (no 'q' or 'Q')
            try:
                array(t._type_)
            except ValueError:
                continue
            a = array(t._type_, [100])

            # v now is an integer at an 'external' memory location
            v = t.from_address(a.buffer_info()[0])
            self.assertEqual(v.value, a[0])
            self.assertEqual(type(v), t)

            # changing the value at the memory location changes v's value also
            a[0] = 42
            self.assertEqual(v.value, a[0]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_numbers.py

示例2: test_char_from_address

# 需要導入模塊: from ctypes import c_char [as 別名]
# 或者: from ctypes.c_char import from_address [as 別名]
def test_char_from_address(self):
        from ctypes import c_char
        from array import array

        a = array('c', 'x')
        v = c_char.from_address(a.buffer_info()[0])
        self.assertEqual(v.value, a[0])
        self.assertTrue(type(v) is c_char)

        a[0] = '?'
        self.assertEqual(v.value, a[0])

    # array does not support c_bool / 't'
    # def test_bool_from_address(self):
    #     from ctypes import c_bool
    #     from array import array
    #     a = array(c_bool._type_, [True])
    #     v = t.from_address(a.buffer_info()[0])
    #     self.assertEqual(v.value, a[0])
    #     self.assertEqual(type(v) is t)
    #     a[0] = False
    #     self.assertEqual(v.value, a[0])
    #     self.assertEqual(type(v) is t) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:25,代碼來源:test_numbers.py

示例3: test_float_from_address

# 需要導入模塊: from ctypes import c_char [as 別名]
# 或者: from ctypes.c_char import from_address [as 別名]
def test_float_from_address(self):
        from array import array
        for t in float_types:
            a = array(t._type_, [3.14])
            v = t.from_address(a.buffer_info()[0])
            self.assertEqual(v.value, a[0])
            self.assertIs(type(v), t)
            a[0] = 2.3456e17
            self.assertEqual(v.value, a[0])
            self.assertIs(type(v), t) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_numbers.py

示例4: test_char_from_address

# 需要導入模塊: from ctypes import c_char [as 別名]
# 或者: from ctypes.c_char import from_address [as 別名]
def test_char_from_address(self):
        from ctypes import c_char
        from array import array

        a = array('c', 'x')
        v = c_char.from_address(a.buffer_info()[0])
        self.assertEqual(v.value, a[0])
        self.assertIs(type(v), c_char)

        a[0] = '?'
        self.assertEqual(v.value, a[0])

    # array does not support c_bool / 't' 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_numbers.py

示例5: test_bool_from_address

# 需要導入模塊: from ctypes import c_char [as 別名]
# 或者: from ctypes.c_char import from_address [as 別名]
def test_bool_from_address(self):
        from ctypes import c_bool
        from array import array
        a = array(c_bool._type_, [True])
        v = t.from_address(a.buffer_info()[0])
        self.assertEqual(v.value, a[0])
        self.assertEqual(type(v) is t)
        a[0] = False
        self.assertEqual(v.value, a[0])
        self.assertEqual(type(v) is t) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_numbers.py

示例6: test_float_from_address

# 需要導入模塊: from ctypes import c_char [as 別名]
# 或者: from ctypes.c_char import from_address [as 別名]
def test_float_from_address(self):
        from array import array
        for t in float_types:
            a = array(t._type_, [3.14])
            v = t.from_address(a.buffer_info()[0])
            self.assertEqual(v.value, a[0])
            self.assertTrue(type(v) is t)
            a[0] = 2.3456e17
            self.assertEqual(v.value, a[0])
            self.assertTrue(type(v) is t) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:12,代碼來源:test_numbers.py

示例7: test_char_from_address

# 需要導入模塊: from ctypes import c_char [as 別名]
# 或者: from ctypes.c_char import from_address [as 別名]
def test_char_from_address(self):
        from ctypes import c_char
        from array import array

        a = array('b', [0])
        a[0] = ord('x')
        v = c_char.from_address(a.buffer_info()[0])
        self.assertEqual(v.value, b'x')
        self.assertIs(type(v), c_char)

        a[0] = ord('?')
        self.assertEqual(v.value, b'?')

    # array does not support c_bool / 't' 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:test_numbers.py


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