我正在尝试在2.7.1版中解决此python语法,但我一直收到ValueError:太多的值无法解包。有人知道我可能做错了吗?
import sys
number_of_outfiles = 100
if __name__ == "__main__":
k = []
for i in range(number_of_outfiles):
k.append(open('/Users/rootrune/Documents/grand' + str(i) + '.csv','w'))
with open(sys.argv[1]) as inf:
for i, line in inf:
if line[-1] == '\n': line = line[:-1]
if i == 0:
headers = line
[x.write(headers + '\n') for x in k]
else:
k[i % number_of_outfiles].write(line + '\n')
[x.close() for x in k]
答案 0 :(得分:2)