1

我的文件(表格)实际上看起来像这样。我想在文件中搜索像“Vonmises”这样的字符串。那就是我要提取的内容的起点。我有 9 个表格,如下所示。现在我可以在我的文件中搜索“Vonmises”字符串,但我的问题是如何提取表格数据和字符串。

我为搜索“Vonmises”字符串编写的代码是:

import re
f_read = open('filename','r')
str='VON MISES'
for line in f_read:    
    m=re.search(str,line)
    if m:
        print line

我的实际表:

                          STRESSES IN QUADRILATERAL ELEMENT

    ELEMNT-ID GRID-ID FIB-DIS STRESSES IN ELEMNT COORD SYS PRINCIPAL STRESSES
                                Norm-X  Norm-Y  Shear-XY     Angle Major Minor Vonmises   
        1         2     45         234    4565    675         65     345   345   54345
                 43     32         444    3243    324         65     453   543   34223 

                           STRESSES IN QUADRILATERAL ELEMENT
   ELEMNT-ID GRID-ID FIB-DIS STRESSES IN ELEMNT COORD SYS PRINCIPAL STRESSES
                                 Norm-X Norm-Y Shear-XY     Angle Major Minor Vonmises   
        2        34    324        342    556     565         546    53   6543   3456
                 45    345        657    676     856         674    65   676    6766

当我执行上面的代码时,我得到的结果是:

  ELEMNT-ID GRID-ID FIB-DIS STRESSES IN ELEMNT COORD SYS PRINCIPAL STRESSES

  ELEMNT-ID GRID-ID FIB-DIS STRESSES IN ELEMNT COORD SYS PRINCIPAL STRESSES

因此,除了上述结果之外,我还想要获取表格值,并且我只想提取 Vonmises 应力列并将其转储到文本文件中。

     ELEMNT-ID GRID-ID FIB-DIS STRESSES IN ELEMNT COORD SYS PRINCIPAL STRESSES
                                Norm-X  Norm-Y  Shear-XY     Angle Major Minor Vonmises   
        1         2     45         234    4565    675         65     345   345   54345
                 43     32         444    3243    324         65     453   543   34223 
4

0 回答 0