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


Python System.Array方法代码示例

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


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

示例1: InitializePath

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def InitializePath(self):
        searchPath = []
        currentDir = Directory.GetCurrentDirectory()
        searchPath.append(currentDir)
        filePathDir = Path.GetDirectoryName(Path.Combine(currentDir, self.fileName))
        searchPath.append(filePathDir)
        entryDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
        searchPath.append(entryDir)
        siteDir = Path.Combine(entryDir, "Lib")
        searchPath.append(siteDir)
        devStdLibDir = Path.Combine(entryDir, '../../External.LCA_RESTRICTED/Languages/IronPython/27/Lib')
        searchPath.append(devStdLibDir)
        dllsDir = Path.Combine(entryDir, "DLLs")
        if Directory.Exists(dllsDir):
            searchPath.append(dllsDir)

        self.engine.SetSearchPaths(Array[str](searchPath)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:run_interactive.py

示例2: test_pass_in_clrarray

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_pass_in_clrarray(self):
        import System
        a1 = System.Array[int]([1,2])
        arrbuff1 = buffer(a1, 0, 5)
        self.assertEqual(1, arrbuff1[0])
        self.assertEqual(2, arrbuff1[1])

        a2 = System.Array[System.String](["a","b"])
        arrbuff2 = buffer(a2, 0, 2)
        self.assertEqual("a", arrbuff2[0])
        self.assertEqual("b", arrbuff2[1])

        self.assertEqual(len(arrbuff1), len(arrbuff2))

        arrbuff1 = buffer(a1, 1, 1)
        self.assertEqual(2, arrbuff1[0])
        self.assertEqual(len(arrbuff1), 1)
        
        arrbuff1 = buffer(a1, 0, -1)
        self.assertEqual(1, arrbuff1[0])
        self.assertEqual(2, arrbuff1[1])
        self.assertEqual(len(arrbuff1), 2)

        a3 = System.Array[System.Guid]([])
        self.assertRaises(TypeError, buffer, a3) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_buffer.py

示例3: test_one_array

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_one_array(self):
        import System
        from Merlin.Testing.BaseClass import IInterface600
        f = IInterface600.m_c

        def checkEqual(first, second):
            self.assertEqual(first, second)
        
        class C(IInterface600):
            def m_c(self, arg):
                if arg:
                    checkEqual(sum(arg), expected)
                    arg[0] = 10

        x = C()
        a = System.Array[int]([1,2])
        expected = 3
        f(x, a)
        self.assertEqual(a[0], 10)
        
        f(x, None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_method_signature.py

示例4: test_system_type_cs0644

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_system_type_cs0644(self):
        # http://msdn2.microsoft.com/en-us/library/hxds244y(VS.80).aspx
        # bug 363984
        import System
        def inheritDelegate():
            class C(System.Delegate): pass

        def inheritArray():
            class C(System.Array): pass

        def inheritValueType():
            class C(System.ValueType): pass

        def inheritEnum():
            class C(System.Enum): pass

        self.assertRaises(TypeError, inheritDelegate)
        self.assertRaises(TypeError, inheritArray)
        self.assertRaises(TypeError, inheritValueType)
        self.assertRaises(TypeError, inheritEnum) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_simplederive.py

示例5: test_type_from_reflection_emit

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_type_from_reflection_emit(self):
        import clr
        import System
        if is_netcoreapp:
            clr.AddReference("System.Reflection.Emit")
        
        sr = System.Reflection
        sre = System.Reflection.Emit
        array = System.Array
        cab = array[sre.CustomAttributeBuilder]([sre.CustomAttributeBuilder(clr.GetClrType(System.Security.SecurityTransparentAttribute).GetConstructor(System.Type.EmptyTypes), array[object]([]))])
        if is_netcoreapp: # no System.AppDomain.DefineDynamicAssembly
            ab = sre.AssemblyBuilder.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.Run, cab)  # tracking: 291888
        else:
            ab = System.AppDomain.CurrentDomain.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.RunAndSave, "temp", None, None, None, None, True, cab)  # tracking: 291888

        mb = ab.DefineDynamicModule("temp", "temp.dll")
        tb = mb.DefineType("EmittedNS.EmittedType", sr.TypeAttributes.Public)
        tb.CreateType()
            
        clr.AddReference(ab)
        import EmittedNS
        EmittedNS.EmittedType() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_reachtype.py

示例6: test_int_minvalue

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [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

示例7: test_str2

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_str2(self):
        # verify we can assign to sys.exc_*
        sys.exc_traceback = None
        sys.exc_value = None
        sys.exc_type = None

        self.assertEqual(str(Exception()), '')


        @skipUnlessIronPython()
        def test_array(self):
            import System
            try:
                a = System.Array()
            except Exception, e:
                self.assertEqual(e.__class__, TypeError)
            else: 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_exceptions.py

示例8: test_interface_inheritance

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_interface_inheritance(self):
        """Verify we can inherit from a class that inherits from an interface"""

        class MyComparer(System.Collections.IComparer):
            def Compare(self, x, y): return 0
        
        class MyDerivedComparer(MyComparer): pass
        
        class MyFurtherDerivedComparer(MyDerivedComparer): pass

        # Check that MyDerivedComparer and MyFurtherDerivedComparer can be used as an IComparer
        array = System.Array[int](range(10))
        
        System.Array.Sort(array, 0, 10, MyComparer())
        System.Array.Sort(array, 0, 10, MyDerivedComparer())
        System.Array.Sort(array, 0, 10, MyFurtherDerivedComparer()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_cliclass.py

示例9: test_type_from_reflection_emit

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_type_from_reflection_emit(self):
        import clr
        import System
        if is_netcoreapp:
            clr.AddReference("System.Reflection.Emit")

        sr = System.Reflection
        sre = System.Reflection.Emit
        array = System.Array
        cab = array[sre.CustomAttributeBuilder]([sre.CustomAttributeBuilder(clr.GetClrType(System.Security.SecurityTransparentAttribute).GetConstructor(System.Type.EmptyTypes), array[object]([]))])
        if is_netcoreapp: # no System.AppDomain.DefineDynamicAssembly
            ab = sre.AssemblyBuilder.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.Run, cab)  # tracking: 291888
        else:
            ab = System.AppDomain.CurrentDomain.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.RunAndSave, "temp", None, None, None, None, True, cab)  # tracking: 291888

        mb = ab.DefineDynamicModule("temp", "temp.dll")
        tb = mb.DefineType("EmittedNS.EmittedType", sr.TypeAttributes.Public)
        tb.CreateType()

        clr.AddReference(ab)
        import EmittedNS
        EmittedNS.EmittedType() 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:24,代码来源:test_reachtype.py

示例10: test_int_minvalue

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [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

示例11: test_interface_inheritance

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_interface_inheritance(self):
        """Verify we can inherit from a class that inherits from an interface"""

        class MyComparer(System.Collections.IComparer):
            def Compare(self, x, y): return 0
        
        class MyDerivedComparer(MyComparer): pass
        
        class MyFurtherDerivedComparer(MyDerivedComparer): pass

        # Check that MyDerivedComparer and MyFurtherDerivedComparer can be used as an IComparer
        array = System.Array[int](list(range(10)))
        
        System.Array.Sort(array, 0, 10, MyComparer())
        System.Array.Sort(array, 0, 10, MyDerivedComparer())
        System.Array.Sort(array, 0, 10, MyFurtherDerivedComparer()) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:18,代码来源:test_cliclass.py

示例12: ghtree_to_list

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def ghtree_to_list(atree):
    """Returns a list representation of a Grasshopper DataTree

    Examples:
        >>> atree=Tree[object]()
        >>> [atree.Add(str("entry: " + str(i)), Path(Array[int]([i]))) for i in range(3)]
        >>> alist = ghtree_to_list(atree)
    """
    def extend_at(path, index, simple_input, rest_list):
        target = path[index]
        if len(rest_list) <= target:
            rest_list.extend([None]*(target-len(rest_list)+1))
        if index == path.Length - 1:
            rest_list[target] = list(simple_input)
        else:
            if rest_list[target] is None:
                rest_list[target] = []
            extend_at(path, index+1, simple_input, rest_list[target])

    all = []
    for i in range(atree.BranchCount):
        path = atree.Path(i)
        extend_at(path, 0, atree.Branch(path), all)
    return all 
开发者ID:compas-dev,项目名称:compas,代码行数:26,代码来源:sets.py

示例13: vector_from_array

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def vector_from_array(a):
        """Make a Matlab-compatible vector from a (Numpy) array.

        Parameters
        ----------
        a : ndarray
            The input array.

        Returns
        -------
        System.Array
            The vector.

        Examples
        --------
        >>>

        """
        raise NotImplementedError 
开发者ID:compas-dev,项目名称:compas,代码行数:21,代码来源:client.py

示例14: to_numpy

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def to_numpy(src):
    """
    Convert .NET array to numpy array

    Parameters
    ----------
    src : System.Array
        
    Returns
    -------
    np.ndarray
        
    """

    src_hndl = GCHandle.Alloc(src, GCHandleType.Pinned)
    try:
        src_ptr = src_hndl.AddrOfPinnedObject().ToInt64()
        bufType = ctypes.c_float * len(src)
        cbuf = bufType.from_address(src_ptr)
        d = np.frombuffer(cbuf, dtype=cbuf._type_)
    finally:
        if src_hndl.IsAllocated:
            src_hndl.Free()

    return d 
开发者ID:DHI,项目名称:mikeio,代码行数:27,代码来源:dotnet.py

示例15: test_len

# 需要导入模块: import System [as 别名]
# 或者: from System import Array [as 别名]
def test_len(self):
        testData = ('hello world', array.array('b', 'hello world'), buffer('hello world'), buffer('abchello world', 3))
        if is_cli:
            import System
            testData += (System.Array[System.Char]('hello world'), )
        
        for x in testData:        
            b = buffer(x, 6)
            self.assertEqual(len(b), 5)
            b = buffer(x, 6, 2)
            self.assertEqual(len(b), 2)

        self.assertEqual(len(buffer("abc", 5)), 0)
        self.assertEqual(len(buffer("abc", 5, 50)), 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_buffer.py


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