我在文本文件中有两列数字,分别是时间和压力列,这是我从 abaqus 有限元包中的分析中得到的!我想在单独的列表(一个时间列表和另一个压力列表)中提取时间列和压力列。然后使用这个列表来做一些其他的数学运算和。. . 我的问题是如何创建这个列表!我的文本文件如下:(文本文件的第一行和其底部的四行为空!)
X FORCE-1
0. 0.
10.E-03 98.3479E+03
12.5E-03 122.947E+03
15.E-03 147.416E+03
18.75E-03 183.805E+03
22.5E-03 215.356E+03
26.25E-03 217.503E+03
30.E-03 218.764E+03
33.75E-03 219.724E+03
37.5E-03 220.503E+03
43.125E-03 221.938E+03
51.5625E-03 228.526E+03
61.5625E-03 233.812E+03
您可以逐行读取文件
time = []
stress = []
count =0
with open("textfile.txt") as file:
for line in file:
line = line.strip() #removing extra spaces
temp = line.split(" ")
if count>=3 and temp[0].strip() : #checking empty string as well
time.append(temp[0].strip()) #removing extra spaces and append
stress.append(temp[len(temp)-1].strip()) #removing extra spaces and append
count+=1
print time
运行在脚本之上的输出
['0.', '10.E-03', '12.5E-03', '15.E-03', '18.75E-03', '22.5E-03', '26.25E-03', '30.E-03', '33.75E-03', '37.5E-03', '43.125E-03', '51.5625E-03', '61.5625E-03']
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句