分类: Python/Ruby
2010-08-18 14:29:18
===================
#!/usr/local/python/bin/python
#-*- encoding: utf-8 -*-
import traceback,sys,re
fh=open('1.out','rb')
ofh=open('1.out.1','wb')
class MyException(Exception):
def __init__(self,code,msg):
self.args=(code,msg)
class NoPositionError(MyException):
pass
class NotUnicodeError(MyException):
pass
def decodestr(todostr):
global i #无法转换时记录下行数
try:
newstr=todostr.decode('
return newstr
except:
t,v,tb=sys.exc_info()
errstr=traceback.format_
print i
if errstr.startswith('
m=re.search(r'position (\d+)[:|-]',errstr)
if m:
redoint=int(m.group(1))
newstr_left=todostr[:redoint].
newstr_mid=todostr[redoint].
newstr_right=decodestr(
newstr = newstr_left+newstr_mid+newstr_
return newstr
else:
raise NoPositionError('',errstr)
else: raise NotUnicodeError('',newstr)
i=0
while 1:
i=i+1
l=fh.readline()
if l:
l=l.strip()
nl=decodestr(l)
print >>ofh,nl
else: break