python IO

读文件

with open('raw.txt','r') as file:
    for line in file.readlines():
        city=line.strip().split()[1]

写文件

with open(args.output, 'w') as file:
    file.write(f'size={args.size}, nhead={args.nhead}, dropout={args.dropout}, batch-size={args.batch_size}\n')
    for nid, name in id_name.items():
        file.write('{}\t{}\n'.format(name, ' '.join(embeddings[nid].astype(str))))
## 格式化处理
1. format

2. %
posted @ 2021-03-01 16:53  zae  阅读(120)  评论(0编辑  收藏  举报