Pythonã¨æ¥æ¬èªè¡¨ç¤ºã¨æåã³ã¼ããunicode ãstr ãutf-8 ãshift-jis ããã
ãPythonã¯ä½¿ããããè¦ããããæ°æã¡ããã¨ã¾ã§è¨ã人ãããããããã«ãã®éãã ã¨æã£ããããããæ¥æ¬èªã使ããã¨ããæã«æ¥ã«æ°æã¡è¯ããªããªããããæããã®ã¯åã ãã§ã¯ãªãã¯ãã ã
ãã¨ãããã¨ã§ä»æ¥ã®æ¥è¨ã®ãã¿ã¯Pythonã¨æ¥æ¬èªã¨ãªãã¾ããã
(WindowsXPã«ココãã "Python 2.5.1 Windows installer" ãã¤ã³ã¹ãã¼ã«ããç°å¢ã§ãã¹ããã¦ãã¾ãã)
- ã¾ãã¯ãããªããæ¸ããã³ã¼ãã¯utf-8ã§ä¿åãããããã¦ããã®ã³ã¼ãã®å é ã«ã¯ä»¥ä¸ãè¨å ¥ããã
# -*- coding: utf-8 -*-
ããªãã¯ã¨ãã£ã¿ã«ä½ã使ã£ã¦ãã¾ããï¼ãç§ä¸¸ãã¡ã¢å¸³ãvimãmeadowãæã㯠Python Scripterãeclipse ï¼ ãããã«ãã¦ããã¡ã¤ã«ãä¿åããæã®ã¨ã³ã³ã¼ãã¯utf-8ã«ãã¹ãã
- ã§ã¯æ©éæ°æã¡ãããªã(表示ãæååãããï¼)ä¾ã
# -*- coding: utf-8 -*- jstr = "æ¥æ¬èª" print jstr #æ¥æ¬èªã表示ãã¦ã¿ãã â æååãããã
ã¡ãã£ã¨æ°æã¡ãããã¦ã¿ãã
# -*- coding: utf-8 -*- jstr = u"æ¥æ¬èª" print jstr #æ¥æ¬èªã表示ãã¦ã¿ãã â æååãããªãã
éãæ¹æ³ã§...
# -*- coding: utf-8 -*- jstr = "æ¥æ¬èª" print jstr.decode('utf-8') #ASCIIâutf-8 ãã¦ããã®ã§ãªã #utf-8âunicode ã«ãã³ã¼ããã¦ããã #æååãããªãã§è¡¨ç¤ºã
éãæ¹æ³ã§...ããã¶ãããããã¡ã°ãæ··ä¹±ããã¨ããããutf-8ãunicodeã«å¤æããããªãã§ãã®ä¸åä¸ã®ãµã³ãã«ã¯ãã³ã¼ãã§ä»åã¯å¤æãªã®ãï¼
# -*- coding: utf-8 -*- jstr = "æ¥æ¬èª" print unicode(jstr,'utf-8') #utf-8âunicodeã«å¤æ #æååãããªãã§è¡¨ç¤ºã
ãã®æ¬¡ã¯ã¨ã©ã¼ã«ãªãããã£ããã¡ã¤ã«ã¯utf-8ã§ä¿åããã¹ãï¼ã¨ãã¦utf-8ã§ä¿åãã¦ãããããshift-jisâunicodeã¯ã¨ã©ã¼ã¨ãªãã
# -*- coding: utf-8 -*- jstr = "æ¥æ¬èª" print unicode(jstr,'shift-jis') #shift-jisâunicodeã«å¤æ #ããã¯ã¨ã©ã¼ã«ãªãã
ããã«ãã¨ã³ã³ã¼ãã£ã¦ã®ãããã
ä¸çªæå¾ã®åè¡ãæååãããã«è¡¨ç¤ºã§ããã®ã¯ç§ã®windowsã®ã³ãã³ãã·ã§ã«ã®ã³ã¼ããã¼ã¸ã cp932 ã ãããããªãã®ç°å¢ã§ã®ã³ã¼ããã¼ã¸ã¯ã³ãã³ãã©ã¤ã³ã§ chcp ã¨ã¿ã¤ããã¦èª¿ã¹ã¦ãã ããã
# -*- coding: utf-8 -*- jstr = u"æ¥æ¬èª" print jstr.encode('iso-2022-jp') print jstr.encode('euc-jp') print jstr.encode('euc-jisx0213') print jstr.encode('euc-jis-2004') print jstr.encode('iso-2022-jp') print jstr.encode('iso-2022-jp-1') print jstr.encode('iso-2022-jp-2') print jstr.encode('iso-2022-jp-3') print jstr.encode('iso-2022-jp-ext') print jstr.encode('iso-2022-jp-2004') print jstr.encode('utf-7') print jstr.encode('utf-8') print jstr.encode('utf-16') print jstr.encode('utf-16-be') print jstr.encode('utf-16-le') print jstr.encode('cp932') #æååãããªãã print jstr.encode('shift-jis') #æååãããªãã print jstr.encode('shift-jisx0213') #æååãããªãã print jstr.encode('shift-jis-2004') #æååãããªãã
ãä»åã¯æååããããã«è¡¨ç¤ºãããã ãã§ãã¡ãã£ã¨æ°æã¡ãããªã£ãããªãã
次回につづく。
åèãªã³ã¯ï¼
åèå³æ¸ï¼
Unicodeæ¨æºå ¥é | |
Tony Graham ç¿æ³³ç¤¾ 2001-05 売ãä¸ãã©ã³ãã³ã° : 167572 ããããå¹³å ISO/IEC 10646 LocalizationãInternationalizationã®èã®å·»ã§ã Amazonã§è©³ããè¦ã by G-Tools |
æåã³ã¼ãè¶ ç 究 | |
ã©ãã«ãº 2003-07 売ãä¸ãã©ã³ãã³ã° : 95525 ããããå¹³å é ããåè ã¾ãã¾ã é¡ä¼¼æã®ä¸ã§ã¯å¤§å¤èªã¿ãããæ¸ç± Amazonã§è©³ããè¦ã by G-Tools |