我有一个列表,想将其写入不带'',[]]的文件中>
d = [['value1', 'value2', 'value3', 'value4', 'LatX', 'LonY', 'HgtZ', 'sats'], ['431.84', '1417', '3.63', '10.28', '47.06446389', '15.45043694', '428.08', '6'], ['438.25', '1416', '3.63', '10.28', '47.06446583', '15.45044000', '428.00', '6'], ['437.64', '1418', '3.63', '9.7', '47.06446583', '15.45044333', '428.03', '6']]
并且在文件中应该看起来像这样:
value1 value2 value3 value4 LatX LonY HgtZ sats 1415 1417 119 337 47.06446389 15.45043694 428.08 6 1436 1416 119 337 47.06446583 15.45044000 428.00 6 1434 1418 119 318 47.06446583 15.45044333 428.03 6
我的代码(Python 3.7):
with open('your_file.txt', 'w') as f: for item in d: f.write("%s\n" % str(item))
此函数逐行打印d中的列表
我有一个列表,想将其写入不带''的文件中,[] d = [['value1','value2','value3','value4','LatX','LonY','HgtZ ','sats'],['431.84','1417','3.63','10 .28','47 .06446389','...
with open('yourfile.txt', 'w') as f:
for list in d:
for s in list :
f.write(str(s) + ' ')
f.write('\n')