[[email protected] test]# cat 1.py fd = open(‘format.txt‘,‘w‘) head = "%10s%10s%10s\n"%(‘id‘,‘name‘,‘record‘) item1 = "%10s%10s%10s\n"%(‘001‘,‘evilxr‘,‘98‘) item2 = "%10s%10s%10s\n"%(‘002‘,‘Python‘,‘88‘) fd.write(head) fd.write(item1) fd.write(item2) fd.close()
[[email protected] test]# cat format.txt id name record 001 evilxr 98 002 Python 88 [[email protected] test]#
Python文件格式化写入
时间: 2024-10-21 18:42:49