Python 当从Aptana Studio PyDev运行时,取消对UnicodeCodeError异常的抑制
以下语句应引发Python 当从Aptana Studio PyDev运行时,取消对UnicodeCodeError异常的抑制,python,django,unicode,python-unicode,Python,Django,Unicode,Python Unicode,以下语句应引发unicodeincodeerror异常: print 'str+{}'.format(u'unicode:\u2019') 在Python shell中,异常按预期引发: >>> print 'str+{}'.format(u'unicode:\u2019') Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> print
unicodeincodeerror
异常:
print 'str+{}'.format(u'unicode:\u2019')
在Python shell中,异常按预期引发:
>>> print 'str+{}'.format(u'unicode:\u2019')
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
print 'str+{}'.format(u'unicode:\u2019')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 8: ordinal not in range(128)
但是如果我从shell执行manage.py runserver
,则会引发异常:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 8: ordinal not in range(128)
是否有某种Python设置可以静默地抑制这些unicode错误
当我直接从Aptana Studio启动Django测试服务器时,如何防止unicode错误被忽略
使用
- Python 2.7.3
- 阿普塔纳工作室3.3.2
print unicode(s)
或者在字符串格式化操作中混合使用unicode和bytestring,如您的示例所示,Python将采用系统默认编码(即ascii
,除非已更改),并隐式尝试使用ascii
编解码器对unicode进行编码/对bytestring进行解码
当前激活的系统默认编码可以用
import sys
sys.getdefaultencoding()
现在看来,Aptana Studio实际上会干扰口译员的默认编码:
从a:
[…]看起来罪魁祸首是PyDev(Eclipse Python插件)。这个
干扰源代码是
.
看起来原因是与Eclipse控制台合作。然而
这件事做得不对。而不是设置控制台编码,
编码被设置为整个Python运行时环境,搞砸了
正在进行开发的目标运行时
这个问题有可能解决。在Eclipse运行…对话框设置中,您可以在Common选项卡上选择Console Encoding。那里
是一个可能的值US-ASCII。我不确定Python 2是怎么想的
“US-ASCII”编码名称,因为默认值为“ASCII”
因此,请确保您将默认设置重置为
ascii
,并且您应该很好。Aptana studio是否会干扰您的解释器的默认编码?什么是导入系统;print sys.getdefaultencoding()
如果您从Aptana内部运行它?@LukasGraf-Ah,这可能就是它。。。阿普塔纳工作室说:UTF-8
。控制台上显示:ascii
。我该如何改变它?哇,那个博客正好击中了我的问题。。。生产unicode的问题,但我不能复制它从开发,直到我找到了原因。。。现在这个修复程序非常有效,谢谢!不客气,很高兴我能帮你找回错误:-)
import sys
sys.getdefaultencoding()