python 學習之編碼轉換和pycharm設置


一編碼轉換

 

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM