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


Python System.Int32方法代码示例

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


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

示例1: test_type_type_is_type

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_type_type_is_type(self):
        class OS: pass
        class NS(object): pass
        
        true_values = [type, NS, int, float, tuple, str]
        if is_cli:
            import System
            true_values += [System.Boolean, System.Int32, System.Version, System.Exception]
        
        for x in true_values:
            self.assertTrue(type(x) is type)
            
        false_values = [OS]
        if is_cli:
            false_values += [ System.Boolean(1), System.Int32(3), System.Version(0, 0), System.Exception() ]
            
        for x in false_values:
            self.assertTrue(type(x) is not type) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_class.py

示例2: test_int_minvalue

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_int_minvalue(self):
        # Test for type of System.Int32.MinValue
        self.assertEqual(type(-2147483648), int)
        self.assertEqual(type(-(2147483648)), long)
        self.assertEqual(type(-2147483648L), long)
        self.assertEqual(type(-0x80000000), int)
        
        self.assertEqual(type(int('-2147483648')), int)
        self.assertEqual(type(int('-80000000', 16)), int)
        self.assertEqual(type(int('-2147483649')), long)
        self.assertEqual(type(int('-80000001', 16)), long)
        
        
        if is_cli:
            import clr
            import System
            
            # verify our str.split doesn't replace CLR's String.Split
            chars = System.Array[str]([' '])
            res = 'a b  c'.Split(chars, System.StringSplitOptions.RemoveEmptyEntries)
            self.assertEqual(res[0], 'a')
            self.assertEqual(res[1], 'b')
            self.assertEqual(res[2], 'c') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_isinstance.py

示例3: test_int_minvalue

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_int_minvalue(self):
        # Test for type of System.Int32.MinValue
        self.assertEqual(type(-2147483648), int)
        self.assertEqual(type(-(2147483648)), long)
        self.assertEqual(type(-long(2147483648)), long)
        self.assertEqual(type(-0x80000000), int)

        self.assertEqual(type(int('-2147483648')), int)
        self.assertEqual(type(int('-80000000', 16)), int)
        self.assertEqual(type(int('-2147483649')), long)
        self.assertEqual(type(int('-80000001', 16)), long)


        if is_cli:
            import clr
            import System

            # verify our str.split doesn't replace CLR's String.Split
            chars = System.Array[str]([' '])
            res = 'a b  c'.Split(chars, System.StringSplitOptions.RemoveEmptyEntries)
            self.assertEqual(res[0], 'a')
            self.assertEqual(res[1], 'b')
            self.assertEqual(res[2], 'c') 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:25,代码来源:test_isinstance.py

示例4: get_values

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def get_values(values, itypes, ftypes):
    """
    This will return structure of values converted to variety of types as a list of tuples:
    [ ...
    ( python_value, [ all_values ] ),
    ... ]

    all_values: Byte, UInt16, UInt32, UInt64, SByte, Int16, Int32, Int64, Single, Double, myint, mylong, myfloat
    """
    all = []
    for v in values:
        sv  = str(v)
        py  = int(v)
        clr = get_clr_values(sv, itypes)
        clr.append(long(py))
        clr.append(myint(py))
        clr.append(mylong(py))
        all.append( (py, clr) )

        py  = long(v)
        clr = get_clr_values(sv, itypes)
        clr.append(py)
        clr.append(myint(py))
        clr.append(mylong(py))
        all.append( (py, clr) )

        py  = float(v)
        clr = get_clr_values(sv, ftypes)
        clr.append(myfloat(py))
        all.append( (py, clr) )

        for imag in [0j, 1j, -1j]:
            py = complex(v + imag)
            all.append( (py, [ py, mycomplex(py) ] ) )

    all.append( (True, [ True ] ))
    all.append( (False, [ False ] ))

    return all 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:41,代码来源:test_numtypes.py

示例5: validate_constructors

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def validate_constructors(self, values):
        types = [Byte, UInt16, UInt32, UInt64, SByte, Int16, Int32, Int64]
        total = 0
        for value in values:
            for first in types:
                v1 = first(value)
                for second in types:
                    v2 = first(second((value)))
                total += 1
        return total 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_numtypes.py

示例6: test_big_1

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_big_1(self):
        from System import SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64
        from System.Numerics import BigInteger
        for (a, m, t,x) in [
                            (7, "ToSByte",  SByte,2),
                            (8, "ToByte",   Byte, 0),
                            (15, "ToInt16", Int16,2),
                            (16, "ToUInt16", UInt16,0),
                            (31, "ToInt32", Int32,2),
                            (32, "ToUInt32", UInt32,0),
                            (63, "ToInt64", Int64,2),
                            (64, "ToUInt64", UInt64,0)
                        ]:

            b = BigInteger(-x ** a )
            left = getattr(b, m)(self.p)
            right = t.MinValue
            self.assertEqual(left, right)

            b = BigInteger(2 ** a -1)
            left = getattr(b, m)(self.p)
            right = t.MaxValue
            self.assertEqual(left, right)

            b = BigInteger(long(0))
            left = getattr(b, m)(self.p)
            right = t.MaxValue - t.MaxValue
            self.assertEqual(left, 0)

            self.assertRaises(OverflowError,getattr(BigInteger(2 ** a ), m),self.p)
            self.assertRaises(OverflowError,getattr(BigInteger(-1 - x ** a ), m),self.p) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_ironmath.py

示例7: test_big_2

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_big_2(self):
        from System import Int32, UInt32, Int64, UInt64
        from System.Numerics import BigInteger
        for (a, m, t,x) in [
                            (31, "ToInt32",Int32,2),
                            (32, "ToUInt32",UInt32,0),
                            (63, "ToInt64",Int64,2),
                            (64, "ToUInt64",UInt64,0)
                        ]:

            b = BigInteger(-x ** a )
            left = getattr(b, m)()
            right = t.MinValue
            self.assertEqual(left, right)

            b = BigInteger(2 ** a -1)
            left = getattr(b, m)()
            right = t.MaxValue
            self.assertEqual(left, right)

            b = BigInteger(long(0))
            left = getattr(b, m)()
            right = t.MaxValue - t.MaxValue
            self.assertEqual(left, right)

            self.assertRaises(OverflowError,getattr(BigInteger(2 ** a ), m))
            self.assertRaises(OverflowError,getattr(BigInteger(-1 - x ** a ), m)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_ironmath.py

示例8: test_multidim_array

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_multidim_array(self):
        import clr
        import System

        md = System.Array.CreateInstance(System.Int32, 2, 2, 2)
        
        for i in range(2):
            for j in range(2):
                for k in range(2):
                    md[i,j,k] = i+j+k
        
        for i in range(2):
            for j in range(2):
                for k in range(2):
                    self.assertTrue(md[i,j,k] == i+j+k) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_index.py

示例9: test_constructor

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_constructor(self):
        array1 = System.Array[int](10)
        array2 = System.Array.CreateInstance(System.Int32, 10)
        self.assertEquals(len(array1), len(array2))
        for i in range(len(array1)):
            self.assertEquals(array1[i], 0)
            self.assertEquals(array1[i], array2[i])

        # 2-dimensional
        array3 = System.Array[System.Byte](3, 4)
        self.assertEquals(array3.Rank, 2)
        for x in range(array3.GetLength(0)):
            for y in range(array3.GetLength(1)):
                self.assertEquals(array3[x, y], 0) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:16,代码来源:test_array.py

示例10: image_to_nparray

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def image_to_nparray(image_like):
    '''returns a 3D numpy.ndarray of floats indexed like [x,y,z]'''
    _shape = (image_like.XSize, image_like.YSize, image_like.ZSize)
    _array = np.zeros(_shape)

    _buffer = Array.CreateInstance(Int32, image_like.XSize, image_like.YSize)
    for z in range(image_like.ZSize):
        image_like.GetVoxels(z, _buffer)
        _array[:, :, z] = to_ndarray(_buffer, dtype=c_int32).reshape((image_like.XSize, image_like.YSize))

    return _array 
开发者ID:VarianAPIs,项目名称:PyESAPI,代码行数:13,代码来源:__init__.py

示例11: GetWindowThreadProcessId

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def GetWindowThreadProcessId(hwnd):
    processId = 0
    pProcessId = Interop.Marshal.AllocHGlobal(Interop.Marshal.SizeOf(processId))
    Interop.Marshal.StructureToPtr(processId, pProcessId, False)
    threadId = Win32_GetWindowThreadProcessId(hwnd, pProcessId)
    if threadId != 0:
        processId = Interop.Marshal.PtrToStructure[System.Int32](pProcessId)
    Interop.Marshal.FreeHGlobal(pProcessId)
    return threadId, processId 
开发者ID:bvn-architecture,项目名称:RevitBatchProcessor,代码行数:11,代码来源:win32_user32.py

示例12: test_safe_length_returns_length_for_net_list

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_safe_length_returns_length_for_net_list():

    a = List[Int32]()
    a.Add(1)
    a.Add(2)
    a.Add(6)

    n = safe_length(a)

    assert n==3 
开发者ID:DHI,项目名称:mikeio,代码行数:12,代码来源:test_helpers.py

示例13: overflowErrorTrigger

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def overflowErrorTrigger(in_type):
    ret_val = {}
    
    ############################################################
    ret_val["VARIANT_BOOL"] =  []
                     
    ############################################################              
    ret_val["BYTE"] = []
    ret_val["BYTE"] += overflow_num_helper(System.Byte)
        
    ############################################################
    #Doesn't seem possible to create a value (w/o 1st overflowing
    #in Python) to pass to the COM method which will overflow.
    ret_val["BSTR"] = [] #["0123456789" * 1234567890]
    
    ############################################################ 
    ret_val["CHAR"] = []
    ret_val["CHAR"] +=  overflow_num_helper(System.SByte)
    
    ############################################################
    ret_val["FLOAT"] = []  
    ret_val["FLOAT"] += overflow_num_helper(System.Double)
    
    #Shouldn't be possible to overflow a double.
    ret_val["DOUBLE"] =  []
    
    
    ############################################################            
    ret_val["USHORT"] =  []
    ret_val["USHORT"] += overflow_num_helper(System.UInt16)
      
    ret_val["ULONG"] =  []
    ret_val["ULONG"] +=  overflow_num_helper(System.UInt32)
               
    ret_val["ULONGLONG"] =  []
    # Dev10 475426
    #ret_val["ULONGLONG"] +=  overflow_num_helper(System.UInt64)
      
    ret_val["SHORT"] =  []
    ret_val["SHORT"] += overflow_num_helper(System.Int16)
      
    ret_val["LONG"] =  []
    # Dev10 475426
    #ret_val["LONG"] += overflow_num_helper(System.Int32)
                
    ret_val["LONGLONG"] =  []
    # Dev10 475426
    #ret_val["LONGLONG"] += overflow_num_helper(System.Int64)
    
    ############################################################
    return ret_val[in_type] 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:53,代码来源:cominterop_util.py

示例14: test_sanity

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_sanity(self):
        '''Make sure that numbers within the constraints of the numerical types are allowed.'''
        import clr
        import System
        temp_list = [   ["System.Byte", 0, 255],
                        ["System.SByte", -128, 127],
                        ["System.Byte", 0, 255],
                        ["System.Int16", -32768, 32767],
                        ["System.UInt16", 0, 65535],
                        ["System.Int32", -2147483648, 2147483647],
                        ["System.UInt32", 0, 4294967295],
                        ["System.Int64", -9223372036854775808, 9223372036854775807],
                        ["System.UInt64", 0, 18446744073709551615],
                        ["System.Single", -3.40282e+038, 3.40282e+038],
                        ["System.Double", -1.79769313486e+308, 1.79769313486e+308],
                        ["System.Decimal", -79228162514264337593543950335, 79228162514264337593543950335],
                        ["int", -2147483648, 2147483647]
                    ]

        for num_type, small_val, large_val in temp_list:
            self.assertTrue(self.num_ok_for_type(1, num_type))
            self.assertTrue(self.num_ok_for_type(1.0, num_type))

            #Minimum value
            self.assertTrue(self.num_ok_for_type(small_val, num_type))
            self.assertTrue(self.num_ok_for_type(small_val + 1, num_type))
            self.assertTrue(self.num_ok_for_type(small_val + 2, num_type))

            #Maximum value
            self.assertTrue(self.num_ok_for_type(large_val, num_type))
            self.assertTrue(self.num_ok_for_type(large_val - 1, num_type))
            self.assertTrue(self.num_ok_for_type(large_val - 2, num_type))

            #Negative cases
            if num_type!="System.Single" and num_type!="System.Double" and num_type!="System.Decimal":
                self.assertTrue(not self.num_ok_for_type(small_val - 1, num_type))
                self.assertTrue(not self.num_ok_for_type(small_val - 2, num_type))
                self.assertTrue(not self.num_ok_for_type(large_val + 1, num_type))
                self.assertTrue(not self.num_ok_for_type(large_val + 2, num_type))

        #Special cases
        self.assertTrue(self.num_ok_for_type(0, "long"))
        self.assertTrue(self.num_ok_for_type(1, "long"))
        self.assertTrue(self.num_ok_for_type(-1, "long"))
        self.assertTrue(self.num_ok_for_type(5, "long"))
        self.assertTrue(self.num_ok_for_type(-92233720368547758080000, "long"))
        self.assertTrue(self.num_ok_for_type( 18446744073709551615000, "long"))

        self.assertTrue(self.num_ok_for_type(0.0, "float"))
        self.assertTrue(self.num_ok_for_type(1.0, "float"))
        self.assertTrue(self.num_ok_for_type(-1.0, "float"))
        self.assertTrue(self.num_ok_for_type(3.14, "float"))
        self.assertTrue(self.num_ok_for_type(-92233720368547758080000.0, "float"))
        self.assertTrue(self.num_ok_for_type( 18446744073709551615000.0, "float")) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:56,代码来源:test_clrnuminterop.py

示例15: test_clrtype_returns_existing_clr_types

# 需要导入模块: import System [as 别名]
# 或者: from System import Int32 [as 别名]
def test_clrtype_returns_existing_clr_types(self):
        '''
        Our implementation of __clrtype__ returns existing .NET types
        instead of subclassing from type or System.Type.
        '''
        global called
        import clr
        import System
        if is_netcoreapp:
            clr.AddReference("System.Collections")
            clr.AddReference("System.Data.Common")
        else:
            clr.AddReference("System.Data")
        
        types = [
                    System.Byte,
                    System.Int16,
                    System.UInt32,
                    System.Int32,
                    System.Int64,
                    System.Double,
                    System.Data.CommandType,
                    System.Data.Common.DataAdapter,
                    System.Boolean,
                    System.Char,
                    System.Decimal,
                    System.IntPtr,
                    System.Object,
                    System.String,
                    System.Collections.BitArray,
                    System.Collections.Generic.List[System.Char],
                    ]

        for x in types:
            called = False
            
            class MyType(type):
                def __clrtype__(self):
                    global called
                    called = True
                    return x
            
            class X(object):
                __metaclass__ = MyType
            
            self.assertEqual(called, True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:48,代码来源:test___clrtype__.py


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