Python入门 NUMECA计算文件处理(一)
批量处理mf文件
读取指定文件目录(包括子目录)下的 "*.mf"文件,并提取指定行到excel表格
思路
- os.walk 递归遍历目标文件夹下的所有文件
- 识别后缀为“.mf”的文件
- 读取特定行数据写入datas(open)
- 使用f.write将读取的矩阵写入指定csv文件
import os
'''
Copy mf文件指定行到excle
'''
def read_data(path, target_lines):
with open(path) as f:
line = f.readline()
line_num = 1
result = []
while line:
if line_num in target_lines:
# target_line hang
i