- 易迪拓培训,专注于微波、射频、天线设计工程师的培养
HFSS15: Using .NET Collection Classes and Interfaces in Python Scripts
Some of the API functions specified above use .Net collection classes and interfaces, that is, Array class, IList interface, IEnumerable interface, and IDictionary interface. The following section describes how to work with the .Net collection objects in Python scripts.
.NET Array, IEnumerable, and IList objects can be indexed and iterated over as if they were Python lists. You can also check for membership using 'in'. To get .Net Array and IList sizes you can use python’s 'len' or .Net ‘Count’.
Example:
Getting size:
arraySize = doubleDataArray.Count
arraySize = len(doubleDataArray)
listSize = sweepsNamesList.Count
listSize = len(sweepsNamesList)
Iterating:
for sweep in sweepsNamesList:
print sweep
for in in xrange(listSize)
print sweepsNamesList[i]
Checking for membership:
if ‘Time’ in sweepsNamesList:
doThis()
else:
doThat()
For .NET IDictionary, the same as for Array and IList, you can get size with ‘len’ or ‘Count’ and check for membership of the keys using 'in'. Getting values for the keys also works the same way as in python ‘dict’.
Example
Getting size:
varValuesSize = varValues.Count
varValuesSize = len(varValues)
Checking for membership:
if ‘offset’ in varValues:
print varValues[‘offset’]
Getting value:
if ‘offset’ in varValues:
offsetValue = varValues[‘offset’]
As for iteration .NET Dictionary is different from python dict. While iterating, python dict will return keys, .Net Dictionary will return .Net KeyValuePair.
Example:
Iterating:
for .Net IDictionary:
for varPair in varValues: #varPair is of .Net KeyValuePair type
varName = varPair.Key
varValue = varPair.Value
for python dict:
for varName in varValues:
varValue = varValues[varName]
You can use python types instead of .Net types if you prefer. For this you need to cast .Net Array and .Net iList to python list type and .Net Dictionary to python dict type.
Casting should not be used for data arrays – it can be extremely costly for the memory usage as well as time consuming.
Example:
aPythonList = list(dotNetArray)
aPythonList = list(dotNetList)
aPythonDict = dict(dotNetDictionary)
HFSS 学习培训课程套装,专家讲解,视频教学,帮助您全面系统地学习掌握HFSS
上一篇:Using additional .NET assemblies
下一篇:Using an IronPython Program for Integration with a Scheduler