waterye

删除最后一行\n

vi,gedit会在最后一行加上\n,实在找不到好的解决方法,只好自己写个shell script删掉
#!/usr/bin/env python
import sys

oldfile
=sys.argv[1]
newfile
=sys.argv[2]
print oldfile,newfile,
print
linecount 
= 0
str 
= ''
= open(oldfile,'r')
for line in f:   
    linecount 
+= 1
= open(oldfile,'r')
for i,line in enumerate(f):
    
if (i==linecount-1):
        str 
+= line.replace('\n','')
#        print line.replace('\n','')
    else:
        str 
+= line
#        print line,
#
print len(str),str
f2 = open(newfile, 'w')
f2.write(str)
quit()


posted on 2008-09-28 19:58 waterye 阅读(1118) 评论(0)  编辑  收藏 所属分类: python


只有注册用户登录后才能发表评论。


网站导航: