我正处于项目中间,我需要在文本中替换包含用户名和密码以及ID号的csv文件,并将其保存在如下文本文件中:
--- CSV:
username;password;id
User1;pass1;11
User2;pass2;12
---文本:
your user name is USER and you password is PASS and your ID is ID
---结果:
Hello your user name is USER1 and you password is PASS1 and your ID is 11
Hello your user name is USER2 and you password is PASS2 and your ID is 12
有什么想法吗? 感谢
答案 0 :(得分:0)
with open(file1) as i, open(file2, 'w') as o:
for line in i:
o.write('Hello your user name is {0} and you
password is {1} and your ID is {2}'.format(*line.split(';')))