使用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.append(row)
答案 0 :(得分: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]]
>>>