First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

Running a separate .py file from python script

asked Sep 24 '15

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?

1 answer

Sort by » oldest newest most voted
1

answered Sep 24 '15

jconto gravatar image

updated Jan 4 '18

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

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 (Jan 4 '18)

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

jconto gravatar imagejconto (Jan 4 '18)

Thanks! It works great!

jeremy.harris.ee gravatar imagejeremy.harris.ee (Jan 5 '18)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Sep 24 '15

Seen: 2,960 times

Last updated: Jan 04 '18