编码的奇怪问题 [英] Strange problems with encoding
问题描述
嗨新闻组,
i我试图替换字符串中的德语特殊字符,例如
str = re.sub('''''','' oe'',str)
当我使用它时,我总是收到消息
UniCode错误:ASCII解码错误:序号不在范围内(128 )
是的,我用Google搜索,我搜索了常见问题解答,手册和python库,并搜索了所有已知的信息。我玩python
内置函数编码来强制执行rigth编码,但错误
保持不变。我已经阅读了很多关于UniCode和内部转换的信息
关于字符串由python完成,但不知何故我错过了线索。
Nope,python说Huuups ...序数没有在范围(128),; - (
你们中的任何人都有任何想法?看起来像我太愚蠢无法阅读
文件。或许我误解了一些事情...
感谢您提前的帮助
Sebastian
Hi newsgroup,
i am trying to replace german special characters in strings like
str = re.sub(''?'', ''oe'', str)
When i work with this, i always get the message
UniCode Error: ASCII decoding error : ordinal not in range(128)
Yes i have googled, i searched the faq, manual and python library and
searched all known soruces of information. I played with the python
builtin function encode to enforce the rigth encoding, but the error
stays the same. I ve read a lot about UniCode and internal conversion
about Strings done by python, but somehow i ve missed the clue.
Nope, python says Huuups... ordinal not in range(128), ;-(
Anyone of you having any idea?? Seems like i am too stupid to read
documentation carefully., perhaps i misunderstand something...
thanks for your help in advance
Sebastian
推荐答案
Sebastian Meyer写道:
Sebastian Meyer wrote:
嗨新闻组,
我想替换像
这样的字符串中的德语特殊字符str = re.sub(''''',''oe'',str)
当我使用它时,我总是收到消息
UniCode错误:ASCII解码错误:序数不在范围内(128)
是的,我用谷歌搜索,我搜索了常见问题,手册和python库,并搜索了所有已知的信息。我玩的是python
BU iltin函数编码以强制执行rigth编码,但错误
保持不变。我已经阅读了很多关于UniCode和内部转换的信息,关于使用python完成的字符串,但不知怎的,我错过了线索。
不,python说Huuups ...序数不在范围内(128),; - (
你们任何人都有任何想法吗?看起来我觉得我太傻了,不能仔细阅读文件。也许我误解了一些事情......
感谢你提前帮助
塞巴斯蒂安
Hi newsgroup,
i am trying to replace german special characters in strings like
str = re.sub(''?'', ''oe'', str)
When i work with this, i always get the message
UniCode Error: ASCII decoding error : ordinal not in range(128)
Yes i have googled, i searched the faq, manual and python library and
searched all known soruces of information. I played with the python
builtin function encode to enforce the rigth encoding, but the error
stays the same. I ve read a lot about UniCode and internal conversion
about Strings done by python, but somehow i ve missed the clue.
Nope, python says Huuups... ordinal not in range(128), ;-(
Anyone of you having any idea?? Seems like i am too stupid to read
documentation carefully., perhaps i misunderstand something...
thanks for your help in advance
Sebastian
我现在正在经历类似的事情。我试着
base64-encode Unicode字符串,我得到完全相同的errormessage。
I''m experiencing something similar for the moment. I try to
base64-encode Unicode strings and I get the exact same errormessage.
s = u''?''
s
u''\xf6''s.encode(''base64'')
Traceback(最近一次调用最后一次):
文件" < interactive input>",第1行,在?
文件" C:\Python23 \lib \ encodings\base64_codec.py",第24行,
base64_encod e $>
输出= base64.encodestring(输入)
文件C:\Python23 \lib\base64.py,第39行,在encodestring中/>
pieces.append(binascii.b2a_base64(chunk))
UnicodeEncodeError:''ascii''编解码器不能编码字符u''\xe9''in br />
位置0:序数不在范围内(128)
当我没有指定它的unicode时它起作用:s =''?''
s
''\ xf6''s.encode(''base64'')
s = u''?''
s u''\xf6'' s.encode(''base64'') Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\encodings\base64_codec.py", line 24, in
base64_encode
output = base64.encodestring(input)
File "C:\Python23\lib\base64.py", line 39, in encodestring
pieces.append(binascii.b2a_base64(chunk))
UnicodeEncodeError: ''ascii'' codec can''t encode character u''\xe9'' in
position 0: ordinal not in range(128)
When I don''t specify it''s unicode it works: s = ''?''
s ''\xf6'' s.encode(''base64'')
''9g = = \ n''
我想对这些unicode字符串进行base64编码的原因是因为我将
作为输入并希望将它们存储在MySQL数据库使用
SQLObject。
''9g==\n''
The reason I want to base64-encode these unicode strings is because I
get those as input and want to store them in a MySQL database using
SQLObject.
" Sebastian Meyer" < S ***** @ technology-network.de>。写道:
"Sebastian Meyer" <s.*****@technology-network.de> writes:
嗨新闻组,
我试图替换字符串中的德语特殊字符,例如
str = re.sub(''?' ',''oe'',str)
Hi newsgroup,
i am trying to replace german special characters in strings like
str = re.sub(''?'', ''oe'', str)
1)str是内置的名称 - 通常是一个坏主意,用它作为
变量名。
2)我认为`str''是一个unicode字符串?尝试将文字写成
u''?''(如果使用Python 2.3,则将相应的编码cookie添加到您的
源文件中)。或者我想你可以写下来吧
你有点{LATIN SMALL LETTER O WITH DIAERESIS}''
干杯,< br $>
mwh
-
Usenet就像是一群表现腹泻的大象 -
巨大的,难以改变的,令人敬畏的,有趣的,以及当你最不想要的时候,b $ ba来源的令人难以置信的粪便量。 - spaf(1992)
1) str is the name of a builtin -- often a bad idea to use that as a
variable name.
2) I presume `str'' is a unicode string? Try writing the literal as
u''?'' instead (and adding the appropriate coding cookie to your
source file if using Python 2.3). Or I guess you could write it
u''\N{LATIN SMALL LETTER O WITH DIAERESIS}''
Cheers,
mwh
--
Usenet is like a herd of performing elephants with diarrhea --
massive, difficult to redirect, awe-inspiring, entertaining, and
a source of mind-boggling amounts of excrement when you least
expect it. -- spaf (1992)
On Thu,2003年11月6日13:39:25 +0000,Michael Hudson写道:
On Thu, 06 Nov 2003 13:39:25 +0000, Michael Hudson wrote:
塞巴斯蒂安迈耶 < S ***** @ technology-network.de>。写道:
"Sebastian Meyer" <s.*****@technology-network.de> writes:
嗨新闻组,
我试图替换字符串中的德语特殊字符,例如
str = re.sub(''?' ',''oe'',str)
1)str是内置的名称 - 将其用作变量名称通常是一个坏主意。
Hi newsgroup,
i am trying to replace german special characters in strings like
str = re.sub(''?'', ''oe'', str)
1) str is the name of a builtin -- often a bad idea to use that as a
variable name.
它只是变量的示例名称,请确保不要
使用任何内置函数作为变量名称
可能不是一个好例子..感谢提示
2)我认为`str''是一个unicode字符串?尝试将文字写成
u''?''(如果使用Python 2.3,则将相应的编码cookie添加到您的
源文件中)。或者我想你可以写它
你在{DATERESIS的拉丁文小写}''
i ll尝试并报告回来.. 。
干杯,
mwh
it was only the example name for the variable, be sure that dont
use any builtins as variable names
maybe not a good example ... thanks for the hint
2) I presume `str'' is a unicode string? Try writing the literal as
u''?'' instead (and adding the appropriate coding cookie to your
source file if using Python 2.3). Or I guess you could write it
u''\N{LATIN SMALL LETTER O WITH DIAERESIS}''
i ll try and report back...
Cheers,
mwh
这篇关于编码的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!