jjCode01 / xer-reader

Read and parse tables in P6 xer file.
GNU General Public License v3.0
9 stars 0 forks source link

Verison of XER #2

Closed etsoft closed 1 week ago

etsoft commented 1 week ago

Hi, with what versions of XER is this tested? I have version 23 now.

This is the script I'm trying to run ::

from xer_reader import XerReader file = r"d:\temp\csv\TACS-NL.xer" reader = XerReader(file) to_csv("d:\temp\temp2")

jjCode01 commented 1 week ago

It's tested on versions 15.2 - 19.12. Are you getting an error? If so, can you copy the error into this issue?

jjCode01 commented 1 week ago

Also, the last line of the script should be reader.to_csv("d:\temp\temp2")

etsoft commented 1 week ago

Hi they error is 👍 Traceback (most recent call last): File "D:\temp\csv\csv.py", line 1, in from xer_reader import XerReader File "C:\Users\ETSoft-4\AppData\Local\Programs\Python\Python312\Lib\site-packages\xer_reader__init__.py", line 3, in from xer_reader.src.reader import XerReader # noqa: F401 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ETSoft-4\AppData\Local\Programs\Python\Python312\Lib\site-packages\xer_reader\src\reader.py", line 7, in import csv File "D:\temp\csv\csv.py", line 1, in from xer_reader import XerReader ImportError: cannot import name 'XerReader' from partially initialized module 'xer_reader' (most likely due to a circular import) (C:\Users\ETSoft-4\AppData\Local\Programs\Python\Python312\Lib\site-packages\xer_reader__init__.py)

jjCode01 commented 1 week ago

Change the name of your script file from csv.py to something like xer_to_csv.py.

Since the xer_reader imports csv from the standard library, I think your script being named csv.py is causing the error.

etsoft commented 1 week ago

I have renamed it , still got an error 👍 D:\temp\csv>python rcsv.py Traceback (most recent call last): File "D:\temp\csv\rcsv.py", line 4, in reader.to_csv("d:\temp\temp2") File "C:\Users\ETSoft-4\AppData\Local\Programs\Python\Python312\Lib\site-packages\xer_reader\src\reader.py", line 169, in to_csv for table in self.to_dict().values(): ^^^^^^^^^^^^^^ File "C:\Users\ETSoft-4\AppData\Local\Programs\Python\Python312\Lib\site-packages\xer_reader\src\reader.py", line 156, in to_dict table = XerTable(table_str) ^^^^^^^^^^^^^^^^^^^ File "C:\Users\ETSoft-4\AppData\Local\Programs\Python\Python312\Lib\site-packages\xer_reader\src\table.py", line 30, in init raise UnrecognizedTable(self.name) xer_reader.src.table.UnrecognizedTable: Unregognized Table: FINTMPL

etsoft commented 1 week ago

I could send you the XER file

jjCode01 commented 1 week ago

Looks like there is a new table in the newer versions of P6. I will work on adding the table.

etsoft commented 1 week ago

Thank you

jjCode01 commented 1 week ago

It will be a while before I can upload the new version. In the meantime you can add a line of code to the script to delete the FINTMPL table before running to_csv. See below.

from xer_reader import XerReader file = r"d:\temp\csv\TACS-NL.xer" reader = XerReader(file) reader.data = reader.delete_tables("FINTMPL") reader.to_csv("d:\temp\temp2")

etsoft commented 1 week ago

Oke, no problem, I working under windows and now I'm getting 👍 Invalid argument: 'd:\temp\temp2\TACS-NL_CURRTYPE.csv' with the double \

Thank you for the effort.

jjCode01 commented 1 week ago

Hmmm. Make sure the temp2 folder exists within the temp folder, and change the last line to reader.to_csv(r"d:\temp\temp2")

jjCode01 commented 1 week ago

Or change the last line to reader.to_csv() The files will be saved in your csv folder.

etsoft commented 1 week ago

Yes is working Thank you

etsoft commented 1 week ago

A nice feature would be to be able to only get some of the tables, please think about this.

jjCode01 commented 1 week ago

Issue closed with version 0.4.0. Added feature to only export certain tables to CSV.