Python文件格式化写入

时间:2014-06-21 08:50:59   收藏:0   阅读:206
[root@localhost 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()

 

[root@localhost test]# cat format.txt 
        id      name    record
       001    evilxr        98
       002    Python        88
[root@localhost test]# 

 

Python文件格式化写入,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!