1 | initial version |
I have a python script where I'm performing acceptance testing of new v34 dynamics models. To do that I run a set of tests with the old model in v33 then run the same tests with the new model in v34. The problem I'm running into is trying to switch PSSE versions mid-script.
Initially I add the v33 BIN and LIB paths to sys.path and os.environ['PATH'] and PSSE intitializes in v33 properly. Next, before I run v34, I remove all v33 paths from sys.path and os.environ, then add in the v34 paths. When I go to initialize PSSE it still has v33 start not v34.
I think it has to do with how the previously imported psspy is still pointing to the v33 location, how do I force python to repoint psspy to the v34 location?
Sample Code:
ver = 33
# Remove old PSSE paths in sys.path and os.environ['PATH']
for p in list(sys.path):
if 'PTI' in p:
sys.path.remove(p)
print 'Removed sys.path Path:' + p
os_paths = os.environ['PATH'].split(';')
for p in list(os_paths):
if 'PTI' in p:
os_paths.remove(p)
print 'Removed os.environ Path:' + p
os.environ['PATH'] = ';'.join(os_paths)
if ver == 33:
strPssePath = '' # path to PSSE program executable
if os.path.exists(r'C:\Program Files (x86)\PTI\PSSE33'): # 32-bit applications
strPssePath = r'C:\Program Files (x86)\PTI\PSSE33'
elif os.path.exists(r'C:\Program Files\PTI\PSSE33'): # 64-bit applications
strPssePath = r'C:\Program Files\PTI\PSSE33'
sys.path.append(os.path.join(strPssePath, 'PSSBIN'))
sys.path.append(os.path.join(strPssePath, 'PSSLIB'))
os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSBIN')
os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSLIB')
elif ver == 34:
strPssePath = '' # path to PSSE program executable
if os.path.exists(r'C:\Program Files (x86)\PTI\PSSE34'): # 32-bit applications
strPssePath = r'C:\Program Files (x86)\PTI\PSSE34'
elif os.path.exists(r'C:\Program Files\PTI\PSSE34'): # 64-bit applications
strPssePath = r'C:\Program Files\PTI\PSSE34'
sys.path.append(os.path.join(strPssePath, 'PSSBIN'))
sys.path.append(os.path.join(strPssePath, 'PSSLIB'))
sys.path.append(os.path.join(strPssePath, 'PSSPY27'))
os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSBIN')
os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSLIB')
import psspy
import redirect
redirect.psse2py()
psspy.psseinit(150000)
(Do some stuff in v33 then repeat code with '34' as the variable ver in the code above)
ver = 34
# Remove old PSSE paths in sys.path and os.environ['PATH']
for p in list(sys.path):
if 'PTI' in p:
sys.path.remove(p)
print 'Removed sys.path Path:' + p
os_paths = os.environ['PATH'].split(';')
for p in list(os_paths):
if 'PTI' in p:
os_paths.remove(p)
print 'Removed os.environ Path:' + p
os.environ['PATH'] = ';'.join(os_paths)
if ver == 33:
strPssePath = '' # path to PSSE program executable
if os.path.exists(r'C:\Program Files (x86)\PTI\PSSE33'): # 32-bit applications
strPssePath = r'C:\Program Files (x86)\PTI\PSSE33'
elif os.path.exists(r'C:\Program Files\PTI\PSSE33'): # 64-bit applications
strPssePath = r'C:\Program Files\PTI\PSSE33'
sys.path.append(os.path.join(strPssePath, 'PSSBIN'))
sys.path.append(os.path.join(strPssePath, 'PSSLIB'))
os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSBIN')
os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSLIB')
elif ver == 34:
strPssePath = '' # path to PSSE program executable
if os.path.exists(r'C:\Program Files (x86)\PTI\PSSE34'): # 32-bit applications
strPssePath = r'C:\Program Files (x86)\PTI\PSSE34'
elif os.path.exists(r'C:\Program Files\PTI\PSSE34'): # 64-bit applications
strPssePath = r'C:\Program Files\PTI\PSSE34'
sys.path.append(os.path.join(strPssePath, 'PSSBIN'))
sys.path.append(os.path.join(strPssePath, 'PSSLIB'))
sys.path.append(os.path.join(strPssePath, 'PSSPY27'))
os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSBIN')
os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSLIB')
import psspy
import redirect
redirect.psse2py()
psspy.psseinit(150000)