Ask Your Question
0

How to use psspy inside a function??

asked 2014-04-28 00:08:46 -0500

Siddhartha gravatar image

updated 2014-04-28 00:38:42 -0500

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)
edit retag flag offensive close merge delete

Comments

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

yfwing gravatar imageyfwing ( 2014-05-15 00:01:11 -0500 )edit

4 answers

Sort by ยป oldest newest most voted
0

answered 2022-11-03 01:06:22 -0500

korean gravatar image

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

edit flag offensive delete link more
0

answered 2016-01-11 21:42:41 -0500

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?

edit flag offensive delete link more
0

answered 2016-01-13 18:20:24 -0500

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.

edit flag offensive delete link more
0

answered 2016-01-12 10:40:03 -0500

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'

edit flag offensive delete link more

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: 2014-04-28 00:08:46 -0500

Seen: 2,882 times

Last updated: Nov 03 '22