草庐IT

SCROLLBAR_POSITION_LEFT

全部标签

python - UnicodeEncodeError : 'ascii' codec can't encode character u'\u201c' in position 34: ordinal not in range(128)

我一直在开发一个从StackOverflow检索问题的程序。直到昨天程序运行良好,但从今天开始我收到错误"MessageFileNameLinePositionTracebackC:\Users\DPT\Desktop\questions.py13UnicodeEncodeError:'ascii'codeccan'tencodecharacteru'\u201c'inposition34:ordinalnotinrange(128)"目前正在显示问题,但我似乎无法将输出复制到新的文本文件中。importsyssys.path.append('.')importstackexchang

python - 如何在 SqlAlchemy 中执行 "left outer join"

我需要执行这个查询::selectfield11,field12fromTable_1t1leftouterjoinTable_2t2ONt2.tbl1_id=t1.tbl1_idwheret2.tbl2_idisnull我在python中有这些类:classTable1(Base):....classTable2(Base):table_id=Column(Integer,ForeignKey('Table1.id',ondelete='CASCADE'),)....我如何从下面到达上面? 最佳答案 q=session.query

python - UnicodeDecodeError : 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

在我的一台机器上,当我使用google应用程序引擎或django时出现错误。例如:app.yamlapplication:demas1252cversion:1runtime:pythonapi_version:1handlers:-url:/imagesstatic_dir:images-url:/cssstatic_dir:css-url:/jsstatic_dir:js-url:/.*script:demas1252c.pydemas1252c.pyimportcgiimportwsgiref.handlersfromgoogle.appengine.ext.webappimpo

python - UnicodeDecodeError : 'ascii' codec can't decode byte 0xc3 in position 23: ordinal not in range(128)

当我尝试连接它时,当字段包含“ñ”或“´”时,我会收到UnicodeDecodeError。如果包含“ñ”或“´”的字段是最后一个,我不会出错。#...nombre=fabricanombre=nombre.encode("utf-8")+'-'+sector.encode("utf-8")nombre=nombre.encode("utf-8")+'-'+unidad.encode("utf-8")#...returnnombre有什么想法吗?非常感谢! 最佳答案 您正在编码为UTF-8,然后重新-编码为UTF-8。Python只

python - 为什么 Pandas 内连接会给出 ValueError : len(left_on) must equal the number of levels in the index of "right"?

我正在尝试将DataFrameA内部连接到DataFrameB并遇到错误。这是我的加入声明:merged=DataFrameA.join(DataFrameB,on=['Code','Date'])这是错误:ValueError:len(left_on)mustequalthenumberoflevelsintheindexof"right"我不确定列顺序是否重要(它们不是真正“有序”的吗?),但以防万一,DataFrame的组织方式如下:DataFrameA:Code,Date,ColA,ColB,ColC,...,ColG,ColH(shape:80514,8-noindex)Da

python 3.2 UnicodeEncodeError : 'charmap' codec can't encode character '\u2013' in position 9629: character maps to <undefined>

我正在尝试制作一个从sqlite3数据库中获取数据的脚本,但我遇到了问题。数据库中的字段是文本类型,并且包含html格式的文本。见下文Yahoo!html{}.yshortcuts{border-bottom:none!important;}.ReadMsgBody{width:100%;}.ExternalClass{width:100%;}VälkommentillYahoo!Mail.Anslutaochdelagårsnabbtochenkeltochärtillgängligtöverallt.Detärlättsomenplättattkommaigång.1.Läggti

python - UnicodeEncodeError : 'ascii' codec can't encode character u'\u2013' in position 3 2: ordinal not in range(128)

我正在使用xlrd解析XSL文件。大多数事情都运行良好。我有一本字典,其中键是字符串,值是字符串列表。所有的键和值都是Unicode。我可以使用str()方法打印大部分键和值。但是有些值有Unicode字符\u2013我得到了上述错误。我怀疑这种情况正在发生,因为这是嵌入在Unicode中的Unicode,Python解释器无法对其进行解码。那么我该如何摆脱这个错误呢? 最佳答案 你也可以打印Unicode对象,你不需要在它周围做str()。假设你真的想要一个str:当您执行str(u'\u2013')时,您正在尝试将Unicode

python - UnicodeDecodeError : 'ascii' codec can't decode byte 0xd1 in position 2: ordinal not in range(128)

我正在尝试处理一个非常大的数据集,其中包含一些非标准字符。根据工作规范,我需要使用unicode,但我很困惑。(而且很可能做错了。)我使用以下方法打开CSV:15ncesReader=csv.reader(open('geocoded_output.csv','rb'),delimiter='\t',quotechar='"')然后,我尝试使用以下代码对其进行编码:name=school_name.encode('utf-8'),street=row[9].encode('utf-8'),city=row[10].encode('utf-8'),state=row[11].encode

python - UnicodeDecodeError : 'ascii' codec can't decode byte 0xef in position 1

我在尝试将字符串编码为UTF-8时遇到了一些问题。我尝试了很多东西,包括使用string.encode('utf-8')和unicode(string),但我得到了错误:UnicodeDecodeError:'ascii'codeccan'tdecodebyte0xefinposition1:ordinalnotinrange(128)这是我的字符串:(。・ω・。)ノ我不知道出了什么问题,知道吗?编辑:问题是按原样打印字符串无法正确显示。另外,当我尝试转换它时出现这个错误:Python2.7.1+(r271:86832,Apr112011,18:13:53)[GCC4.5.2]onli

python - UnicodeDecodeError : 'ascii' codec can't decode byte 0xe2 in position 13: ordinal not in range(128)

我正在使用NLTK对我的文本文件执行kmeans聚类,其中每一行都被视为一个文档。例如,我的文本文件是这样的:belongfingerdeathpunchhastymikehastywallsjerichojägermeisterrulesrulesbandsfollowperformingjägermeisterstageapproach现在我要运行的演示代码是这样的:importsysimportnumpyfromnltk.clusterimportKMeansClusterer,GAAClusterer,euclidean_distanceimportnltk.corpusfro