2008年01月01日 星期二 03:02
ǰ¼¸Ìì¿´µ½ÓÐÈËÍÆ¼öemacs ¾ÍÊÔÓÃÁËÏ windowsÏ ÔÚemacsµÄshellÏÂÔËÐÐpython½Å±¾µÄʱºò»á³öÏÖuniocde´íÎó ±ÈÈç test.pyÀïÓÐÈçÏÂÄÚÈÝ: a=u'ÄãºÃ' print a ÔÚemacsµÄshellÀïÔËÐÐ python test.py ±¨´í£º Traceback (most recent call last): File "test.py", line 28, inprint a UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) µ«ÊÇÔÚwindowsµÄcmdÀïÔËÐÐÔòÕý³£ ÓÐÓöµ½¹ýͬÑùÇé¿öµÄô£¿ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080101/f8a7789d/attachment.htm
2008年01月01日 星期二 17:24
On Jan 1, 2008 3:02 AM, lee <flyli3415在gmail.com> wrote: > ǰ¼¸Ìì¿´µ½ÓÐÈËÍÆ¼öemacs ¾ÍÊÔÓÃÁËÏ > > windowsÏ > > ÔÚemacsµÄshellÏÂÔËÐÐpython½Å±¾µÄʱºò»á³öÏÖuniocde´íÎó > ±ÈÈç test.pyÀïÓÐÈçÏÂÄÚÈÝ: > > a=u'ÄãºÃ' > print a > > ÔÚemacsµÄshellÀïÔËÐÐ python test.py ±¨´í£º > Traceback (most recent call last): > File "test.py", line 28, in> print a > UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: > ordinal not in range(128) > > µ«ÊÇÔÚwindowsµÄcmdÀïÔËÐÐÔòÕý³£ > > ÓÐÓöµ½¹ýͬÑùÇé¿öµÄô£¿ > ÄãµÄÎļþÀïûÓж¨Òåutf8 -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080101/813951c0/attachment.html
2008年01月01日 星期二 20:55
文件开始的地方写上文件编码类型 # *-* coding: utf-8 *-* On Jan 1, 2008 5:24 PM, Ben Luo <benluo在gmail.com> wrote: > > > On Jan 1, 2008 3:02 AM, lee <flyli3415在gmail.com> wrote: > > > > 前几天看到有人推荐emacs 就试用了下 > > > > windows下 > > > > 在emacs的shell下运行python脚本的时候会出现uniocde错误 > > 比如 test.py里有如下内容: > > > > a=u'你好' > > print a > > > > 在emacs的shell里运行 python test.py 报错: > > Traceback (most recent call last): > > File "test.py", line 28, in> > print a > > UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: > ordinal not in range(128) > > > > 但是在windows的cmd里运行则正常 > > > > 有遇到过同样情况的么? > 你的文件里没有定义utf8 > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -- Jerry Lee University of Jinan
2008年01月01日 星期二 22:58
ÕâÑù×ö»¹ÊDz»ÐÐ Òª°Ñ a=u'ÄãºÃ' ¸Ä³É a='ÄãºÃ' µ«ÊÇÕâÓ¦¸Ã²»ÊÇÖ÷ÒªÎÊÌâ Èç¹û´ÓÒ»¸öÎļþ¶ÁÈ¡unicodeµÄ×Ö·û ÔÙÏëÒÔ print a.decode('utf-16') ¾ÍÓÖ²»ÐÐÁË µ«ÊÇÔÚIDLE £¬pythonwind£¬cmd ÏÂÊÇÕý³£µÄ£¬Ö»ÓÐemacsµÄshellϲ»Õý³£ ÔÚ08-1-1£¬Ben Luo <benluo在gmail.com> дµÀ£º > > ÄãµÄÎļþÀïûÓж¨Òåutf8 > > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080101/1bf1ed30/attachment.html
Zeuux © 2025
京ICP备05028076号