Ask Your Question
0

Running a separate .py file from python script

asked 2015-09-24 14:24:11 -0500

J.Armstrong gravatar image

I am building automation for running PSS/e from a Python program. I can call the psspy.runrspnsfile(rspname) to run a response file. I have not found nor figured out how to run a .py file from the automation. Does anyone know how to pass a python change file?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-09-24 15:38:40 -0500

jconto gravatar image

updated 2018-01-04 14:27:33 -0500

You can use the function 'execfile' to call a second python from a primary one. If psspy is used in the second python file, it will have to be imported explicitly. calling a second.py:

 execfile(second.py,globals(),locals())    #globals and local can be omitted

All variables available in primary.py will be made available also to second.py!!
Now, at the beginning of second.py:

sys.path.append(r'C:\Program Files (x86)\PTI\PSSE33\PSSBIN')  # psse\bin path where psspy is located
import psspy
#psspy.psseinit(80000) #only if psse was not started
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
_s = psspy.getdefaultchar()
edit flag offensive delete link more

Comments

Follow-up question to the execfile(). In my second.py, let's say I'm using the API for psspy.bus_data_2() and I have some data that I want to use the default data (i.e. _i, _f). I'm getting the NameError that '_i' and '_f' are not defined. What's my work around to get this data to set to defaults?

jeremy.harris.ee gravatar imagejeremy.harris.ee ( 2018-01-04 11:26:58 -0500 )edit

Check updated answer above. Use (after importing psspy): _i = psspy.getdefaultint() or _f = psspy.getdefaultreal() or _s = psspy.getdefaultchar()

jconto gravatar imagejconto ( 2018-01-04 14:21:35 -0500 )edit

Thanks! It works great!

jeremy.harris.ee gravatar imagejeremy.harris.ee ( 2018-01-05 10:19:03 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2015-09-24 14:24:11 -0500

Seen: 2,928 times

Last updated: Jan 04 '18