我当前的代码:
def write_from_dict(users_folder):
for key, value in value_dict.items(): # iterate over the dict
file_path = os.path.join(users_folder, key + '.txt')
with open(file_path, 'w') as f: # open the file for writing
for line in value: # iterate over the lists
f.write('{}\n'.format(line))
我当前的输出:
['4802', '156', '4770', '141']
['4895', '157', '4810', '141']
['4923', '156', '4903', '145']
我想要的输出:
4802,156,4770,141
4895,157,4810,141
4923,156,4903,145
所以基本上我想删除空格''和[]。
最佳答案
更换
f.write('{}\n'.format(line))
用
f.write('{}\n'.format(",".join(line)))
关于python - 我如何调整代码以仅删除所需的打印值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49014617/