首页 > 编程语言 > 详细

Python修改文本列对齐

时间:2017-06-15 22:40:28      阅读:429      评论:0      收藏:0      [点我收藏+]
letter                   ->             
LadderScore0                   ->       
LadderScore1                   ->       
LadderScore2                   ->       
LadderScore3                   ->       
LadderScore4                   ->       
LadderScore5                   ->       
LadderScore6                   ->       
LadderScore7                   ->       
LadderScore8                   ->       
LadderScore9                   ->       
WeeklyDoneCount0                   ->   
WeeklyDoneCount1                   ->   
WeeklyDoneCount2                   ->   
WeeklyDoneCount3                   ->   
WeeklyDoneCount4                   ->   
WeeklyDoneCount5                   ->   
WeeklyDoneCount6                   ->   
WeeklyDoneCount7                   ->   
WeeklyDoneCount8                   ->   
WeeklyDoneCount9                   ->   
LastFPS0                   ->           
LastFPS1                   ->           
LastFPS2                   ->           
LastFPS3                   ->           
LastFPS4                   ->           
LastFPS5                   ->           
LastFPS6                   ->           
LastFPS7                   ->           
LastFPS8                   ->           
LastFPS9                   ->


脚本内容如下

#!/usr/bin/env python
#coding:utf-8

import os
format = ‘%-*s%-*s\n‘
file = open(‘a.txt‘,‘r‘)
f = open(‘file.txt‘,‘a‘)
all = ""
for i in file:
    i=i.split(‘ ‘)
    a = format % (20, i[0], 20, ‘->‘)
    all += a
    f.write(a)
f.close()
file.close()
print all


文件展示

技术分享


本文出自 “YHT的运维笔记” 博客,请务必保留此出处http://yht1990.blog.51cto.com/9014030/1937288

Python修改文本列对齐

原文:http://yht1990.blog.51cto.com/9014030/1937288

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!