Python PSS/E获取输出作为变量 [英] Python PSS/E get output as variable

查看:102
本文介绍了Python PSS/E获取输出作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是电源工程师,我经常在PSS/E程序中使用python.我堆积如山,我希望您能以程序员的身份提供帮助.我有这个小代码:

I am power engineer and I often use python in PSS/E program. I am stacked and I want your help as programmers. I have this small code:

import os,sys

PSSE_LOCATION = r"C:\Program Files\PTI\PSSE33\PSSBIN"
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['PATH'] + ';' +  PSSE_LOCATION

import psspy
import redirect
redirect.psse2py()

#--------------------------------
# PSS/E Saved case

CASE = r"""D:\xxx\Desktop\TESTING\SUMMAX.sav"""

if __name__ == '__main__':
    psspy.psseinit(2000)
    psspy.case(CASE)
    psspy.fnsl(
        options1=0, # disable tap stepping adjustment.
        options5=0, # disable switched shunt adjustment.
    )
    psspy.fdns([0,0,0,1,1,0,99,0])
    psspy.area_2(0,1,1)

代码redirect.psse2py()在控制台中打印程序报告.您能帮我把这些输出作为变量吗?

Code redirect.psse2py() prints the program report in Console. Can you help me to get those outputs as variable?

推荐答案

鉴于我对PSSE不太了解,可以尝试以下方法:

Given I don't know much about PSSE, you can try the following:

import sys
import io

out, err = io.StringIO(), io.StringIO()
sys.stdout = out
sys.stderr = err

# rest of your code here

# once your code is finished

results = out.getvalue()
errors = err.getvalue()

这篇关于Python PSS/E获取输出作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆