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

Ask Your Question
0

How to use psspy inside a function??

asked Apr 28 '14

Siddhartha gravatar image

updated Apr 28 '14

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 ...
(more)

Comments

Could be because of the format of file temp. Can you post the contents of temp?

yfwing gravatar imageyfwing (May 15 '14)

4 answers

Sort by » oldest newest most voted
0

answered Nov 3 '2

korean gravatar image

You must enter "import psspy" at the top of the temp file.

link
0

answered Jan 12 '16

bad_hand gravatar image

Is the module psspy being used in temp? Could it be that psspy used in temp (if that is the case) cause that error?

link
0

answered Jan 14 '16

sheng gravatar image

A NameError suggested that it is not a path issue. It means that psspy is not defined in one of the scripts that you have used, i.e. meaning you didn't even try to import psspy.

If the path is not correct, it should throw an ImportError when you try to import psspy.

link
0

answered Jan 12 '16

jconto gravatar image

It could be the path for psspy:

yours:psse_path=r'C:\Program Files\PTI\PSSE33\PSSBIN'

in my pc:psse_path=r'C:\Program Files (x86)\PTI\PSSE33\PSSBIN'

link

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: Apr 28 '14

Seen: 2,921 times

Last updated: Nov 03 '22