我要合并两个文本文件:名称.txt以及studentid.txt文件你知道吗
名称包含:
Timmy Wong, Johnny Willis, Jason Prince
那个studentid.txt文件包含:
B5216, B5217, B5218
我想把它们合并成一个新的文本文件叫做studentlist.txt文件使用这种格式,我只希望所有逗号都变成竖条
Student_Name Student_ID
Timmy Wong | B5216
Johnny Willis | B5217
Jason Prince | B5218
到目前为止,我真的不知道如何格式化这个阅读了一些指南和我的书,但它真的没有帮助太多。你知道吗
到目前为止我就是这么做的
def main():
one = open( "names.txt", 'r' )
lines = one.readlines()
two = open( "studentid.txt", 'r' )
lines2 = two.readlines()
outfile = open( "studentlist.txt", 'w' )
outfile.write( "Student_Name StudentID")
outfile.writelines( lines + lines2 )
main()
输出变成
Student_Name StudentIDTimmy Wong, Johnny Willis, Jason Prince
B5216, B5217, B218
我是个初学者,所以请对我宽容一点>;<
输出:
未经测试,但您希望类似于:
相关问题 更多 >
编程相关推荐