1

使用python 2.7,我可以从文件名列表中读取多个csv...

empty = []
for i in items:
    with open(i) as file:
        reader = csv.reader(file, dialect='excel')
        for row in reader:
            print row

这打印得很好...

['myfile.csv', 'a', '4', '50.0', 10.0]
['myfile2.csv', 'b', '2', '20.0', 50.0]
......

现在,如果我想将此打印的列表附加到一个空的第二个列表(empty=[]),我该如何格式化它,使它看起来像上面的输出(带有漂亮整洁的列)。目前,当我添加时,它是一个大而长的连续输出行empty.append(row)

4

1 回答 1

0

尝试使用 pprint:

>>> from pprint import pprint as pp
>>> a = [1,2,3,4,4,5,5,6,6,7]
>>> pp(a)
[1, 2, 3, 4, 4, 5, 5, 6, 6, 7]

>>> b = [a, a, a]
>>> pp(b)
[[1, 2, 3, 4, 4, 5, 5, 6, 6, 7],
 [1, 2, 3, 4, 4, 5, 5, 6, 6, 7],
 [1, 2, 3, 4, 4, 5, 5, 6, 6, 7]]
>>> 
于 2013-05-23T12:50:19.497 回答