【【Python】【BugList12】python自带IDLE执行print(req.text)报错:UnicodeEncodeError: 'UCS-2' codec can&#】教程文章相关的互联网学习教程文章

有没有办法使用Python在SQLite中正确排序unicode字符串?

有一种简单的方法可以在SQLite中使用unicode数据来排序行吗?解决方法:SQLite有一个BYOS(自带分拣机)策略.请参阅more details的FAQ.他们选择不包括(默认情况下)任何支持Unicode的排序算法,以保持SQLite库的轻松和易于静态链接. 但是,您可以在create a collator,但是请您排序,然后告诉SQLite使用它.正如另一张海报所暗示的那样,源代码树中有一些使用ICU执行此操作的合作者.但是,您也可以使用自己的,如果您使用像GLib这样具有自己的U...

python – str和unicode之间的区别:为什么Redis在传递unicode时会返回二进制数据?【代码】

关于数据类型str和unicode之间的区别,在two questions之后,我仍然对以下内容感到困惑. 在第1区,我们看到城市的类型是unicode,正如我们所期望的那样. 然而在块2中,在通过磁盘往返(redis)之后,城市的类型是str(并且表示是不同的). 将utf-8存储在磁盘上,读入unicode,然后用utf-8写回的dogma在某处失败了. 为什么类型(城市)的第二个实例是str而不是unicode? 同样重要的是,这有关系吗?您是否关心您的变量是unicode还是str,或者只要代码...

我可以在Python中将SQLite用于字符串而不是用于TEXT的unicode吗?

AFAIK SQLite在Python中为TEXT返回unicode对象.是否有可能让SQLite返回字符串对象?解决方法:在进一步检查Python SQLite API时,我发现了这一点: http://docs.python.org/library/sqlite3.html#sqlite3.Connection.text_factory 案件结案.

python – Pymssql,如何使用它从MSSQL2008读取unicode数据【代码】

我在ubuntu-10.10上使用了pymssql-1.0.2和freetds-0.82.7.另外,我在windows-7上有一个mssql2008服务器.我可以使用pymssql和freetds从ubuntu连接mssql.但是我无法从mssql数据库中获取unicode数据.数据库排序规则是Cyrillic_General_CI_AS. 我的freetds.conf文件如下所示:[mssql2008]host=10.0.0.34port=1433tds version=7.0我的代码看起来像这样:conn = pymssql.connect(host=10.0.0.34\mssql2008, user=***, password=***, datab...

python – Django:Unicode,MySQL和编码(latin1,koi8-r)【代码】

Django 2.0版. Python 3 我的数据库charset和collat??ion:mysql> SELECT @@character_set_database, @@collation_database; +--------------------------+----------------------+ | @@character_set_database | @@collation_database | +--------------------------+----------------------+ | latin1 | latin1_swedish_ci | +--------------------------+----------------------+老开发人员使用Perl在KOI8...

Python,mysqldb和unicode【代码】

我无法从mysql查询中获取unicode值. 我现在就是这样做的:>>> from MySQLdb import connect >>> from MySQLdb.cursors import DictCursor >>> con = connect(passwd = "****",db = 'my_db',user = "db_user",host = "localhost",cursorclass = DictCursor,use_unicode=True,charset="utf8" ) >>> cursor = con.cursor () >>> cursor.execute (u'Select * from basic_applet') >>> res = cursor.fetchall() >>> print(res) ({'Title...

python – 使用unicode参数的cx_Oracle’ORA-01843:不是有效月份’【代码】

我有以下内容:(使用ipython)In [30]: con = cx_Oracle.connect('refill_test02/******@MYDB')In [31]: cur = con.cursor()In [32]: cur.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'")In [33]: cur.execute("select to_date(:0), to_timestamp(:1) from dual", ['2013-03-12', '2013-03-12 08:22:31.332144']) Out[33]: <__builtin__.OracleCursor o...

python – 使用pandas.read_sql的UnicodeDecodeError【代码】

UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 8: character maps to <undefined>我在一个简单的SQL查询中看到了错误:df = pd.read_sql(query,connection)我通常在sql开发人员上尝试了这个查询,它的工作原理非常好..这里真的难以理解如何在read_sql调用中指定编码 我使用的是Python 3.4和pandas版本0.14.1 非常感谢!解决方法:根据oracle docs,您的数据库的正确编码是iso-8859-1所以当你将()连接到你的...

PowerShell与Python中的Unicode? Windows中的替代shell?【代码】

我想要一个在Windows上支持Unicode的shell.它出货的PowerShell似乎没有. PowerShell V2(Windows 7 x64):PS C:\> powershell Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved.PS C:\> python Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> unicode_char=unichr(0xf12)...

Python unicode在OSX上的2.6.1中工作,但在Ubuntu上的2.6.5中不工作【代码】

鉴于从Python解释器运行以下代码:import sys sys.getdefaultencoding() my_string = '\xc3\xa9' my_string = unicode(my_string, 'utf-8') my_string print my_string在Python上运行Python 2.6.1,一切正常:$python Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getdefaul...

为什么UnicodeEncodeError只在emacs的python shell中引发?【代码】

在emacs中(使用run-python命令调用python3):>>> sys.version sys.version '3.2.3 (v3.2.3:3d0686d90f55, Apr 10 2012, 11:25:50) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]' >>> sys.getdefaultencoding() sys.getdefaultencoding() 'utf-8' >>> data data 'sp\xe4m' >>> print(data) print(data) Traceback (most recent call last):File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode ...

python – 在Windows中检测带有Unicode字符的文件名【代码】

Python版本:2.7.3 文件名:测试雪人角色 – ? – .mp3 经过以下测试,其中没有一个被证明是成功的.>>> os.path.exist('test snowman character --?--.mp3') False >>> os.path.exist(repr('test snowman character --?--.mp3')) False >>> os.path.isfile('test snowman character --\\xe2\\x98\\x83--.mp3') False >>> os.path.isfile(r'test snowman character --\\xe2\\x98\\x83--.mp3') False >>> os.path.isfile('test snowm...

python – unicode字符串中的内存位置【代码】

我知道有人在我创作时解释原因Python 2.7中相同的unicode字符串它们没有指向内存中的相同位置与“普通”字符串一样>>> a1 = 'a' >>> a2 = 'a' >>> a1 is a2 True好吧那就是我的预期,但是>>> ua1 = u'a' >>> ua2 = u'a' >>> ua1 is ua2 False为什么?怎么样?解决方法:不保证正常字符串被中断.有时他们是,有时他们不是.规则很复杂,特定于版本,故意没有记录. 你可以依赖这样一个事实,即只要一个好主意,Python就会尝试实现常用的小对象...