infile = open("test",'r')
line = infile.read()
newline = ""
for i in range(0,len(line)):
c1 = ord(line[i])
if c1 > 0x7e or c1 < 0x20:
if c1 == 0x0a or c1 == 0x0d:
newline += line[i]
else:
newline += " "
else:
newline += line[i]
print newline
import string
import re
pattern_empty = """^\s*$"""
pattern_head = """^\s+"""
pattern_tail = """\s+$"""
reg_empty = re.compile(pattern_empty,re.MULTILINE)
reg_head = re.compile(pattern_head,re.MULTILINE )
reg_tail = re.compile(pattern_tail,re.MULTILINE)
newline, num = reg_empty.subn("<br>",newline)
newline, num = reg_head.subn(" ",newline)
newline, num = reg_tail.subn(" ",newline)
print newline
print num
星期六, 十一月 24, 2007
订阅:
博文评论 (Atom)
0 comments:
发表评论