# Read file
with open('filename.txt', 'r') as f:
raw_data = f.read()
# Seperate each experiment
experiments = raw_data.split('\n\n')
# Split lines
experiments = [lines.split('\n') for lines in experiments]
# Create empty list for all.
all_data = []
for experiment in experiments:
# Create empty list for each experiment.
data = {'t':[], 'x':[]}
for line in experiment:
# if the first character of line is not a number, ignore ( for #t, x )
if (not line[0].isdigit()): continue
# split and convert data into int
t, x = map(int,line.split(' '))
# append it
data['t'].append(t)
data['x'].append(x)
# append it
all_data.append(data)
2条答案
按热度按时间iaqfqrcu1#
在阅读数据时没有直接的方法来分割,但是你可以读取整个文件并利用空白行来分割框架:
字符串
输出量:
型
ru9i0ody2#
字符串