I'm new to python programming. I am working on a text file which was the result file of a software. Basically whenever we work on that software it write all the messages to the result text file(similar to a log file).
Now my problem is that the file has many tables like the one below:
it may have some million lines above
* ============================== INERTIA ==============================
* File: /home/hamanda/transfer/cradle_vs30_dkaplus01_fwd_dl140606_fem140704_v00.bif
* Solver: Nastran
* Date: 24/09/14
* Time: 10:29:50
* Text:
*
* Area +1.517220e+06
* Volume +5.852672e+06
*
* Structural mass +4.594348e-02
* MASS elements +0.000000e+00
* NSM on property entry +0.000000e+00
* NSM by parts (VMAGen and MPBalanc) +0.000000e+00
* NSM by NSMCreate +0.000000e+00
* Total mass +4.594348e-02
*
* Center of gravity
* in the global +1.538605e+02 +3.010898e+00 -2.524868e+02
* coordinate system
*
* Moments of inertia +8.346990e+03 +6.187810e-01 +1.653922e+03
* about the global +6.187810e-01 +5.476398e+03 +4.176218e+01
* coordinate system +1.653922e+03 +4.176218e+01 +7.746156e+03
*
* Steiner share +2.929294e+03 +4.016500e+03 +1.088039e+03
*
* Moments of inertia +5.417696e+03 +2.190247e+01 -1.308790e+02
* about the center +2.190247e+01 +1.459898e+03 +6.835397e+00
* of gravity -1.308790e+02 +6.835397e+00 +6.658117e+03
* ---------------------------------------------------------------------
some lines below and this table may repeat if user does any change to area and volume
values.----------
Now my question is how can i print the latest table on the console. i'm able to print the first occurence of the table and now i'm not able to get the latest occurence of the table.
I need the latest table to be printed on the console how can i do it? This is my code:
input = open(fileName,'r')
intable = False
for line in input:
if line.strip() == "* ============================== INERTIA ==============================":
intable = True
if line.strip() == "* ---------------------------------------------------------------------":
intable = False
break
if intable and line.strip().startswith("*"):
z1=(line.strip())
print(z1)