相关疑难解决方法(0)

删除Python unicode字符串中重音的最佳方法是什么?

我在Python中有一个Unicode字符串,我想删除所有的重音符号(变音符号).

我在Web上发现了一种在Java中执行此操作的优雅方法:

  1. 将Unicode字符串转换为长标准化形式(字母和变音符号使用单独的字符)
  2. 删除Unicode类型为"变音符号"的所有字符.

我是否需要安装pyICU等库?或者只使用python标准库?那python 3怎么样?

重要说明:我想避免代码使用重音字符到非重音符号的显式映射.

python unicode diacritics python-2.x python-3.x

462
推荐指数
12
解决办法
23万
查看次数

在Python中将Unicode转换为ASCII而没有错误

我的代码只是抓取一个网页,然后将其转换为Unicode.

html = urllib.urlopen(link).read()
html.encode("utf8","ignore")
self.response.out.write(html)
Run Code Online (Sandbox Code Playgroud)

但我得到一个UnicodeDecodeError:


Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 507, in __call__
    handler.get(*groups)
  File "/Users/greg/clounce/main.py", line 55, in get
    html.encode("utf8","ignore")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 2818: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)

我认为这意味着HTML包含一些在某处错误形成的Unicode尝试.我可以删除导致问题的任何代码字节而不是出错吗?

python unicode ascii utf-8 character-encoding

170
推荐指数
9
解决办法
46万
查看次数

在python中将文本文件的编码从utf-8转换为ansi或unicode

我有一个 utf-8 编码的文本文件。我想在python中自动将它的unicode更改为ANSI或unicode。是否可以?我该怎么做?

python encoding text ansi utf-8

4
推荐指数
2
解决办法
2万
查看次数