[問題] 中文編碼的疑惑..
剛學習python
print 中文的問題一直困擾著我
但又解決不了
我的ide 是 eclispe + pydev
我寫了一個test code為
=========python code=======
#-*- coding: utf-8 -*-
print '科科'
===========================
存檔編碼,我是選utf8
用windows cmd 執行 出來的結果為
蝘?
如果換成 print u'科科'
就可以了@@ 所以我一直到處找 如何直接 print '科科' 就能正常顯示
去python.tw的mail list問 有人回答說 把 lib/site.py裡面的
def setencoding(): 改成下面這樣就可以
===================================================
def setencoding():
"""Set the string encoding used by the Unicode implementation. The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "ascii" # Default value set by _PyUnicode_Init()
if 1:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0:
# Enable to switch off string to Unicode coercion and implicit
# Unicode to string conversion.
encoding = "undefined"
if encoding != "ascii":
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
===================================================
不過改過了還是不行在windows cmd 底下跑出正確的 '科科' 兩個字 >"<
希望有人可以幫我解惑一下 thx
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.134.110.252
→
11/17 19:36, , 1F
11/17 19:36, 1F
推
11/17 19:41, , 2F
11/17 19:41, 2F
→
11/17 19:44, , 3F
11/17 19:44, 3F
→
11/17 19:45, , 4F
11/17 19:45, 4F
→
11/17 19:46, , 5F
11/17 19:46, 5F
→
11/17 20:36, , 6F
11/17 20:36, 6F
推
11/17 20:46, , 7F
11/17 20:46, 7F
→
11/17 21:33, , 8F
11/17 21:33, 8F
推
11/18 23:09, , 9F
11/18 23:09, 9F
推
11/25 14:19, , 10F
11/25 14:19, 10F
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章