Search code examples
pythonoutputconsole-applicationpsse

Python PSS/E get output as variable


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)

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


Solution

  • 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()