I have a difficult mission for a beginner in Python, I need to import a table from a source file which is written in LaTex. I was thinking I will use the name of the table as identifier, and then write line by line into an array, from the beginning of the table to its end. What is the "natural" way to do this job?
The astropy package has a LaTeX table reader.
from astropy.table import Table
tab = Table.read('file.tex')
The reader function should automatically recognize the format and read the first table in the file. (Cut and paste the relevant section into a new file if you want a later table).
The reader has some limitations, though. Most importantly, every row of data has to be on a single line (The link to the table in the questions is dead, so I cannot see if this is a problem) and there cannot be commands like \multicolumn
or \multirow
.
Check the docs for Latex reading in astropy for more options: https://astropy.readthedocs.org/en/latest/api/astropy.io.ascii.Latex.html#astropy.io.ascii.Latex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With