Skip to content

把分词结果保存到文本文档出现编码问题 #10

@GoogleCodeExporter

Description

@GoogleCodeExporter
如下
#def cuttest(s):
    #wlist = seg.cut(s)
    #wlist.reverse()
    #tmp = "/".join(wlist)
    #print tmp      
    #print "================================================================="        
if __name__=="__main__":
    s1 = file("text1.txt").read()
    wlist = seg.cut(s1)
    wlist.reverse()
    res1 = "/".join(wlist)
    print res1   

    fl=open("result.txt","w")
    fl.write(tmp)
    fl.close()   

取消定义的cuttext模块,下面直接引用,读取文本text1中的内��
�分词,都是可行的。
但是最后三行把分词结果保存到result.txt中出现编码问题:
   UnicodeEncodeError: 'ascii' codec can't encode character u'\ufeff' in position 0: ordinal not in range(128)
不知道怎么解决啊,前辈能不能帮忙看看怎么修改。



Original issue reported on code.google.com by [email protected] on 1 Jun 2013 at 5:14

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions