-4
4

2 回答 2

0

在python中应该是这样的。

import csv
fo = csv.writer(open('out.csv','wb'))
with open('eg.txt', 'r') as f:
    for line in f:
        assert line[:3] == '00I'
        buf = []
        for i in range(88):
            line = f.next()
            buf.append(line.strip()[2:])

        line = f.next()
        assert line[:3] == 'A00'
        line = f.next()
        assert line[:3] == 'A10'
        line = f.next()
        assert line[:3] == 'A21'
        fo.writerow(buf)
于 2012-07-04T19:04:55.080 回答
0

如果您绝对确定每个条目是 92 行长:

from itertools import izip
import csv

with open('data.txt') as inf, open('data.csv','wb') as outf:
    lines = (line[2:].rstrip() for line in inf)
    rows = (data[1:89] for data in izip(*([lines]*92)))
    csv.writer(outf).writerows(rows)
于 2012-07-04T19:14:54.430 回答