How to use psspy inside a function??
Hello People,
I defined a function in python which was supposed to do some tasks. Inside the function I was using the API routines but i am getting the error " Name Error: global name "psspy" not defined". This is happening when i am importing a file named temp and using certain parts of it. Without the file temp, it works fine, bust since temp file is an integral part of the whole project i have to use it. Now how do i make psspy run inside the function without getting such an error.
NOTE:- This code is being run through command prompt. That is probably the place where problem lies. When i am running in python shell, the code works fine
#Files Necessary for GUI part of this CODE
from Tkinter import *
import tkMessageBox
import Tkinter
import Tkinter, tkMessageBox
import tkFileDialog
import temp
#Calling of the PSSE location in Python and also informing PSSE about its environment
import os
import sys
psse_path=r'C:\Program Files\PTI\PSSE33\PSSBIN'
sys.path.append(psse_path)
os.environ['PATH']+=';'+psse_path
print "\n"
import psspy
psspy.throwPsseException=True
import redirect
redirect.psse2py()
psspy.psseinit(8000)
psspy.case(temp.filenam)
from psspy import _i
from psspy import _f
from psspy import _s
print "\n"
print temp.con_file
print "***********************************************************\n\n\n"
def TS1_S1_LOADRELIEF():
l1=psspy.loddt2(7824,"1",'TOTAL','ACT')
l2=psspy.loddt2(8032,"1",'TOTAL','ACT')
l3=psspy.loddt2(8033,"1",'TOTAL','ACT')
l4=psspy.loddt2(7928,"1",'TOTAL','ACT')
l5=psspy.loddt2(7865,"1",'TOTAL','ACT')
L1=l1[1].real+l2[1].real+l3[1].real+l4[1].real+l5[1].real
l1=psspy.loddt2(36591,"1",'TOTAL','ACT')
l2=psspy.loddt2(36588,"1",'TOTAL','ACT')
L2=l1[1].real+l2[1].real
l1=psspy.loddt2(36576,"1",'TOTAL','ACT')
psspy.bsys(1,0,[0.0,0.0],0,[],5,[7824,8032,8033,7928,7865],0,[],0,[])
psspy.scal_2(1,0,1,[0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0])
psspy.scal_2(0,1,2,[_i,1,0,4,0],[L1-150,0.0,0.0,-.0, 67.0,-.0, 0.95])
psspy.bsys(1,0,[0.0,0.0],0,[],2,[36591,36588],0,[],0,[])
psspy.scal_2(1,0,1,[0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0])
psspy.scal_2(0,1,2,[_i,1,0,4,0],[L2-220,0.0,0.0,-.0,0.0,-.0, 0.95])
psspy.bsys(1,0,[0.0,0.0],0,[],1,[36576],0,[],0,[])
psspy.scal_2(1,0,1,[0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0])
psspy.scal_2(0,1,2,[_i,1,0,4,0],[l1[1].real-100,0.0,0.0,-.0,0.0,-.0, 0.95])
def calculate_PI():
s=0
psspy.fnsl([0,0,0,1,0,0,0,0])
ival=psspy.solved()
print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"
print ival
print ...
Could be because of the format of file temp. Can you post the contents of temp?