파이썬에서 유니코드 문서를 읽고 쓰는법
By SeukWon Kang
1 import os,sys,string 2 import codecs 3 4 5 fncodec = codecs.getdecoder(“utf_16”) 6 7 fd = codecs.open( “unicode file.txt” , “r” , “utf_16” ) 8 utext = fd.readlines() 9 fd.close() 10 11 utext2 = [] 12 13 for i in utext : 14 if “Search String” in i: 15 utext2.append(i) 16 17 print len(utext),len(utext2) 18 19 fd = codecs.open( “unicode out.txt” , “w”,“utf_16” ) 20 fd.writelines(utext2) 21 fd.close()
별거 아니지만 자주 쓸 일이 있을것 같아서. ^^