unicode()和u''。encode(),bug的不同编码? [英] different encodings for unicode() and u''.encode(), bug?
问题描述
你好!
i偶然发现了这种情况,即如果我解码了一些字符串,在
下面只是空字符串,使用mcbs编码,它成功了,但如果我用b $ b尝试用相同的编码对其进行编码,那么令人惊讶的是它会因为LookupError而无法使用
。这似乎有待纠正的事情?
$ python
Python 2.5.1(r251:54869,2007年4月18日,22:08:04)< darwin上的
[GCC 4.0.1(Apple Computer,Inc。build 5367)]
类型help,copyright,credit等等。或许可证或欲获得更多信息。
Hello!
i stumbled on this situation, that is if I decode some string, below
just the empty string, using the mcbs encoding, it succeeds, but if I
try to encode it back with the same encoding it surprisingly fails
with a LookupError. This seems like something to be corrected?
$ python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>> s =''''
unicode(s, ''mcbs'')
>>s = ''''
unicode(s, ''mcbs'')
u''''
u''''
>> unicode(s,''mcbs'')。encode(''mcbs'')
>>unicode(s, ''mcbs'').encode(''mcbs'')
Traceback(最近一次调用最后一次):
文件"< stdin>",第1行,< module>
LookupError:未知编码:mcbs
祝大家2008年好!
mario
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
LookupError: unknown encoding: mcbs
Best wishes to everyone for 2008!
mario
推荐答案
python
Python 2.5.1(r251:54869,2007年4月18日,22:08:04)
[GCC 4.0 .d(Apple Computer,Inc。build 5367)]在darwin上
输入help,copyright,credit等等。或许可证或欲获得更多信息。
python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>> s =''''
unicode(s, ''mcbs'')
>>s = ''''
unicode(s, ''mcbs'')
u''''
u''''
>> unicode(s,''mcbs'')。encode(''mcbs'')
>>unicode(s, ''mcbs'').encode(''mcbs'')
Traceback(最近一次调用最后一次):
文件"< stdin>",第1行,< module>
LookupError:未知编码:mcbs
祝大家2008年好!
mario
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
LookupError: unknown encoding: mcbs
Best wishes to everyone for 2008!
mario
我偶然发现了这种情况,即如果我解码一些字符串,在
i stumbled on this situation, that is if I decode some string, below
只是空字符串,使用mcbs编码,它成功,但是如果我用b $ b尝试使用相同的编码对其进行编码,则会出乎意料地失败带有LookupError的
。这似乎有待纠正的事情?
just the empty string, using the mcbs encoding, it succeeds, but if I
try to encode it back with the same encoding it surprisingly fails
with a LookupError. This seems like something to be corrected?
确实 - 在您的代码中。它的编码不一样。
Indeed - in your code. It''s not the same encoding.
>>> unicode(s ,''mcbs'')
>>>unicode(s, ''mcbs'')
u''''
u''''
>>> unicode(s,''mcbs'')。encode(''mcbs'')
>>>unicode(s, ''mcbs'').encode(''mcbs'')
回溯(最近一次调用最后一次):
文件"< stdin>",第1行,< module>
LookupError:未知编码:mcbs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
LookupError: unknown encoding: mcbs
使用" mbcs"在第二个电话中,不是mcbs。
HTH,
Martin
Use "mbcs" in the second call, not "mcbs".
HTH,
Martin
On 1月2日上午9:30,Martin v.L?wis < mar ... @ v.loewis.dewrote:
On Jan 2, 9:30 am, "Martin v. L?wis" <mar...@v.loewis.dewrote:
使用" mbcs"在第二次通话中,不是mcbs。
Use "mbcs" in the second call, not "mcbs".
哎呀,对不起,当我在翻译中测试它时
我输错了mbcs用mcbs。但是我一直这样说;-)
I.e.它仍然是相同的编码,即使可能不存在..?
如果我再次尝试使用mbcs一直以来,我仍然得到同样的错误:
Ooops, sorry about that, when i switched to test it in the interpreter
I mistyped "mbcs" with "mcbs". But remark I did it consistently ;-)
I.e. it was still teh same encoding, even if maybe non-existant.. ?
If I try again using "mbcs" consistently, I still get the same error:
这篇关于unicode()和u''。encode(),bug的不同编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!