python 实现 Fortran的读取10*0以及换行读问题

思路,用read来全部读取,然后替换带*的元素来解决。代码如下

 

import numpy as np
import re
inf = open('SF.usr')
title = inf.readline()
l = inf.read()
d = re.split('[^0-9.*]+',l.strip())
for i,x in enumerate(d):
    if x.find('*') != -1 :
        f = x.split('*')
        number = int(f[0])
        value = f[1]
        print(i,number,'',value)
        d[i] = value
        for t in range( 1 , number):
            d.insert(i,value)
d = np.array(d,dtype= np.float64)

 

posted @ 2018-03-14 22:36  Anlovescode  阅读(588)  评论(0编辑  收藏  举报