Ask Your Question
0

Output table to Excel file through python

asked 2023-12-01 04:38:28 -0500

Zhnoob gravatar image

Hi, am trying to use the python to output the result from psse output file to an excel file, I have already create a output file "SMIBBESSfault" which is used to read as the object to record data to excel (The channel I want to record is the frequenct and the active power, so I set the channel as 1,2,5,6 in the code).

The code I am using is as following:

import os,sys
import win32com.client
outfile = r"""SMIB_BESS_fault.out"""
psseversion = 34

 if psseversion== 34 or psseversion== 33:
   exec('import psse%s'%psseversion)
 else:
   pssepath = r"C:\Program Files (x86)\PTI\PSSE%s\PSSBIN"%psseversion
   if pssepath not in sys.path:
       sys.path.append(pssepath)

import psspy
import dyntools
import matplotlib.pyplot as plt

chnfobj = dyntools.CHNF(outfile)
short_title, chanid, chandata = chnfobj.get_data()
chnfobj.xlsout(channels=[1,2,5,6],show=False)

I am confused, because the error don't always occur, sometimes it just keep happened, sometimes it happens when running the code for a few times and without any change.

Whenever the error occur, the error message is always as following:

Exception has occurred: com_error

(-2147418111, '\xb1\xb5\xa6\xac\xaa\xcc\xa4w\xa9\xda\xb5\xb4\xb3o\xad\xd3\xa9I\xa5s\xa1C', None, None) File "C:\Users\POWER\Desktop\p\simp 3 change xsource\chanplot22.py", line 42, in <module> chnfobj.xlsout(channels=[1,2,5,6],show=False)

Will the problem relate with the version of win32com module? Because after searching for a bit, the "com_error" seems relate with this module, but I still can't solve the problem.

Any suggestion will be much appreciate! Thanks!

Link for the outfile (google drive): https://drive.google.com/file/d/1kly0...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2023-12-01 08:50:12 -0500

jconto gravatar image

Re-install modules that behave unreliably (extreme: re-install PSSe). I simplified your code below, using an existing out file and able to create a XLS file:

import psse34
import dyntools

#outfile = r"""SMIB_BESS_fault.out"""
outfile = r'outs\\bess_A_Qp_load_trip.out'
chnfobj = dyntools.CHNF(outfile)
short_title, chanid, chandata = chnfobj.get_data()
chnfobj.xlsout(channels=[1,2,5,6],show=False)
edit flag offensive delete link more

Comments

Thanks for the answer, if I am trying to the code provide here, there is no need to use the "pywin32" module right? And after I have tried the code here, it returned the excatly same error message as before.

Zhnoob gravatar imageZhnoob ( 2023-12-03 04:27:03 -0500 )edit

Does the module "psse34" and "dyntools" are install with the software together?Which means I can only re-install PSSe might be the best choise. Thanks!

Zhnoob gravatar imageZhnoob ( 2023-12-03 04:29:04 -0500 )edit

I think pywin32 is used by dyntools. "psse34" and "dyntools" are part of the PSSe installation.

jconto gravatar imagejconto ( 2023-12-03 13:54:43 -0500 )edit

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

1 follower

Stats

Asked: 2023-12-01 04:38:28 -0500

Seen: 363 times

Last updated: Dec 01 '23