脚本如下所示:
#add powerfactory.pyd path to python path
import sys
sys.path.append("C:\\Program Files\\DIgSILENT\\PowerFactory 2017
SP2\\Python\\3.6")
if __name__ == "__main__":
#import powerfactory module
import powerfactory
#start powerfactory module in unattended mode (engine mode)
app=powerfactory.GetApplication()
#active project
project=app.ActivateProject('Python Test') #active project "Python Test"
# prj=app.GetActiveProject #returns the actived project
#run python code below
ldf=app.GetFromStudyCase('ComLdf') #calling loadflow command
ldf.Execute() #executing the load flow command
#get the list of lines contained in the project
lines=app.GetCalcRelevantObjects('*.ElmLne') #returns all relevant objects
for line in lines: #get each element out of list
name=line.loc_name #get name of the line
value=line.GetAttribute('c:loading')
print('Loading of the line: %s = %.2f%%'%(name,value))
只需输入:
>>>name
返回的结果是最后一个元素:
>>>'Line3'
我也尝试过使用dict(),但它仍然无效。因此,如果有人能给我一些建议,我们将非常感激。
答案 0 :(得分:0)
您可能希望最后一个for循环看起来像这样:
{{1}}
这不会覆盖每个循环迭代的name值。