一編碼轉換
unicode 可以編譯成 UTF-U GBK
即
#!/usr/bin/env python # _*_ coding:utf-8 _*_ __author__ = 'Administrator' a='方' #默認是utf-8 a_unicod=a.decode('utf-8') # decode是解碼成unicode 括號是腳本內容的默認編碼 即:將腳本內容的utf-8解碼成unicode a_gbk=a_unicod.encode('gbk') #encode是編碼,將unicode的編碼內容編碼成指定的,這里是gbk print(a_gbk) #用於終端打印
#print(u"方") #3里面是字符串 2里面是unicode
# 3版本直接將utf-8編碼成GBK 不需要先轉成unicode了,因為3沒有了
E:\py_test\s2_py>python3 test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
a_unicod=a.decode('utf-8') # decode是解碼成unicode 括號是腳本內容的默認編碼 即:將腳本內容的utf-8解碼成unicode
AttributeError: 'str' object has no attribute 'decode'
四 pycharm 安裝 配置
file-setings-editor- file && file encode template 輸入
#!/usr/bin/env python # _*_ coding:utf-8 _*_ __author__ = 'superfang'
五 pycharm 快捷鍵
ctrl+/ 批量注釋
shift+方向鍵 選中
shift+tab 向左tab