Python unidecode生成额外的\n

2024-06-08 11:15:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用下面的代码从字符串中删除重音符号。 输入(inp)是一个带有带重音符号的字符串的文件。 输出(outp)是一个文件。你知道吗

代码如下:

49 def remove_unidecode(inp, outp):
50     ''' Remove accent and special characters
51     + lower case '''
52     print "# remove accents"
53     for line in inp:
54         uline = unicode(line, 'utf-8')
55         udline = unidecode(uline)
56         outp.write(udline.lower())
57     outp.close()

问题是unidecode正在创建额外的\n,即打印额外的换行符:

$ wc -l *
3619 inp.txt
3879 outp.txt

有人知道为什么会这样吗?你知道吗


Tags: 文件字符串代码txtdeflinelowerremove