草庐IT

unicode_normalize

全部标签

python - 关于 unicode 和 utf-8 编码,python 中的 `%` 格式运算符和 `str.format()` 之间有区别吗?

假设n=u"Tübingen"repr(n)#`T\xfcbingen`#Unicodei=1#integer以下文件中的第一个抛出UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\xfc'inposition82:ordinalnotinrange(128)当我执行n.encode('utf8')时,它会起作用。第二个在这两种情况下都完美无缺。#PythonFile1##!/usr/bin/envpython-B#encoding:utf-8print'{id},{name}'.format(id=i,name=n)#Pyth

python 2.X : Why Can't I Properly Handle Unicode?

我已经尝试了一段时间Python2.X和unicode。但我已经到了没有意义的地步。第一个问题:一些代码会清楚地解释我的意思。txt变量在这里模拟pyqt4的翻译功能。它返回一个QString。#-*-coding:utf-8-*-fromPyQt4importQtCoretxt=QtCore.QString(u'puòessere/sarà/日本語')txtUnicode1=unicode(txt,errors='replace')txtUnicode2=unicode(txt)当print()-ing两个unicode字符串时,我得到:pu�essere/sar�/???puòes

python - subprocess.Popen 带有 unicode 路径

我有一个要打开的unicode文件名。以下代码:cmd=u'cmd/c"C:\\Pok\xe9mon.mp3"'cmd=cmd.encode('utf-8')subprocess.Popen(cmd)返回>>>'C:\Pokיmon.mp3'isnotrecognizedasaninternalorexternalcommand,operableprogramorbatchfile.即使文件确实存在。为什么会这样? 最佳答案 看起来您使用的是Windows和Python2.X。使用os.startfile:>>>importos>>

python - 如何消除 ☎ unicode?

在网络抓取和去除所有html标签后,我得到了unicode中的黑色电话字符\u260e(☎)。但不像thisresponse我也想摆脱它。我在Scrapy中使用了以下正则表达式来消除html标签:pattern=re.compile("| |&",re.DOTALL|re.M)然后我尝试匹配\u260e,我想我被thebackslashplague捕获了.我尝试了这种模式但没有成功:pattern=re.compile("| |&|\u260e",re.DOTALL|re.M)pattern=re.compile("| |&|\\u

python - 去除 unicode 字符修饰符

在Python中从unicode字符串中去除字符修饰符的最简单方法是什么?例如:A͋͠r͍̞̫̜͌ͦ̈͐ͅt̼̭͞h́u̡̙̞̘̙̬͖͓rͬͣ̐ͮͥͨ̀͏̣应该成为亚瑟我尝试了这些文档,但我找不到任何可以做到这一点的东西。 最佳答案 试试这个importunicodedataa=u"STRINGGOESHERE"#usinganactualstringwouldbreakstackoverflow'scodeformatting.u"".join(xforxinaifnotunicodedata.category(x).starts

确保 python 2 和 3 中的 unicode 的 Pythonic 方法

我正在努力移植一个库,使其与python2和3兼容。该库从调用应用程序接收字符串或类似字符串的对象,我需要确保将这些对象转换为unicode字符串。在python2中我可以这样做:unicode_x=unicode(x)在python3中我可以这样做:unicode_x=str(x)然而,我最好的跨版本解决方案是:defensure_unicode(x):ifsys.version_info这当然看起来不太好(尽管它有效)。有更好的解决方案吗?我知道unicode_literals和u前缀,但这两种解决方案都不起作用,因为输入来自客户端并且不是我库中的文字。

python - 如何从 Python 字符串中去除 unicode "punctuation"

这就是问题所在,我有一个unicode字符串作为pythonsqlite查询的输入。查询失败(“喜欢”)。结果是字符串“FRANCE”没有6个字符,它有7个。而第七个是。..unicodeU+FEFF,零宽不间断空格。我究竟如何在查询之前捕获一类这样的东西? 最佳答案 您可以将unicodedata类别用作Python中unicode数据表的一部分:>>>unicodedata.category(u'a')'Ll'>>>unicodedata.category(u'.')'Po'>>>unicodedata.category(u',

python - 向 mysql 插入 4 字节 unicode 引发的警告

请看以下内容:/home/kinka/workspace/py/tutorial/tutorial/pipelines.py:33:Warning:Incorrectstringvalue:'\xF0\x9F\x91\x8A\xF0\x9F...'forcolumn't_content'atrow1n=self.cursor.execute(self.sql,(item['topic'],item['url'],item['content']))字符串'\xF0\x9F\x91\x8A,实际上是一个4字节的unicode:u'\U0001f62a'。mysql的字符集是utf-8但插入

python - Flask - header 未转换为 unicode?

我正在使用python开发一个小型网络服务:flask(0.8版)StormORM(0.19版)带有mod_wsgi的Apache我有一个自定义的HTTPheader,Unison-UUID,我有时会用它来检索我的数据库中的信息。这是我遇到问题的(为简单起见略微重写的)片段:uuid=flask.request.headers['Unison-UUID']store=storm.locals.Store(my_database)user=store.get(models.User,uuid)类User大致是这样的:classUser(Storm):uuid=Unicode(primar

python - Unicode、正则表达式和 PyPy

我写了一个程序来添加(有限)unicodesupport到Python正则表达式,虽然它在CPython2.5.2上运行良好,但在PyPy上运行不正常(1.5.0-alpha01.8.0,实现Python2.7.12.7。2),两者都在WindowsXP上运行(编辑:如评论中所示,@dbaupp可以在Linux上正常运行)。我不知道为什么,但我怀疑这与我对u"和ur"的使用有关。完整来源是here,相关位是:#-*-coding:utf-8-*-importre#RegexpstomatchcharactersintheBMPaccordingtotheirUnicodecategor