Python
  • Introduction
  • Chapter 1.Notes from research
    • 1.Introduction of Python
    • 2. Build developer environment
      • 2.1.Sublime Text3
      • 2.2.Jupyter(IPython notebook)
        • 2.2.1.Introduction
        • 2.2.2.Basic usage
        • 2.2.3.some common operations
      • 2.3.Github
        • 2.3.1.Create Github account
        • 2.3.2.Create a new repository
        • 2.3.3.Basic operations: config, clone, push
      • 2.4.Install Python 3.4 in Windows
    • 3. Write Python code
      • 3.1.Hello Python
      • 3.2.Basic knowledges
      • 3.3.撰寫獨立python程式
      • 3.4.Arguments parser
      • 3.5.Class
      • 3.6.Sequence
    • 4. Web crawler
      • 4.1.Introduction
      • 4.2.requests
      • 4.3.beautifulSoup4
      • 3.4.a little web crawler
    • 5. Software testing
      • 5.1. Robot Framework
        • 1.1.Introduction
        • 1.2.What is test-automation framework?
        • 1.3.Robot Framework Architecture
        • 1.4.Robot Framework Library
        • 1.5.Reference
    • 6. encode/ decode
      • 6.1.編碼/解碼器的基本概念
      • 6.2.常見的編碼/ 解碼錯誤訊息與其意義
      • 6.3 .處理文字檔案
    • 7. module
      • 7.1.Write a module
      • 7.2.Common module
        • 7.2.1.sched
        • 7.2.2.threading
    • 8. Integrate IIS with django
      • 8.1.Integrate IIS with django
  • Chapter 2.Courses
    • 2.1.Python for Data Science and Machine Learning Bootcamp
      • 2.1.1.Virtual Environment
      • 2.1.2.Python crash course
      • 2.1.3.Python for Data Analysis - NumPy
        • 2.1.3.1.Numpy arrays
        • 2.1.3.2.Numpy Array Indexing
        • 2.1.3.3.Numpy Operations
      • 2.1.4.Python for Data Analysis - Pandas
        • 2.1.4.1.Introduction
        • 2.1.4.2.Series
        • 2.1.4.3.DataFrames
        • 2.1.4.4.Missing Data
        • 2.1.4.5.GroupBy
        • 2.1.4.6.Merging joining and Concatenating
        • 2.1.4.7.Data input and output
      • 2.1.5.Python for Data Visual Visualization - Pandas Built-in Data Visualization
      • 2.1.6.Python for Data Visualization - Matplotlib
        • 2.1.6.1.Introduction of Matplotlib
        • 2.1.6.2.Matplotlib
      • 2.1.7.Python for Data Visualization - Seaborn
        • 2.1.7.1.Introduction to Seaborn
        • 2.1.7.2.Distribution Plots
        • 2.1.7.3.Categorical Plots
        • 2.1.7.4.Matrix Plots
        • 2.1.7.5.Grids
        • 2.1.7.6.Regression Plots
      • 2.1.8. Python for Data Visualization - Plotly and Cufflinks
        • 2.1.8.1.Introduction to Plotly and Cufflinks
        • 2.1.8.2.Plotly and Cufflinks
      • 2.1.9. Python for Data Visualization - Geographical plotting
        • 2.1.9.1.Choropleth Maps - USA
        • 2.1.9.2.Choropleth Maps - World
      • 2.1.10.Combine data analysis and visualization to tackle real world data sets
        • 911 calls capstone project
      • 2.1.11.Linear regression
        • 2.1.11.1.Introduction to Scikit-learn
        • 2.1.11.2.Linear regression with Python
      • 2.1.12.Logistic regression
        • 2.1.12.1.Logistic regression Theory
        • 2.1.12.2.Logistic regression with Python
      • 2.1.13.K Nearest Neighbors
        • 2.1.13.1.KNN Theory
        • 2.1.13.2.KNN with Python
      • 2.1.14.Decision trees and random forests
        • 2.1.14.1.Introduction of tree methods
        • 2.1.14.2.Decision trees and Random Forests with Python
      • 2.1.15.Support Vector Machines
      • 2.1.16.K means clustering
      • 2.1.17.Principal Component Analysis
    • 2.2. Machine Learning Crash Course Jam
Powered by GitBook
On this page
  • 1.Introduction
  • 2.Python的操作

Was this helpful?

  1. Chapter 1.Notes from research
  2. 6. encode/ decode

6.1.編碼/解碼器的基本概念

1.Introduction

  • 編碼(encode) /解碼(decode)

    • 編碼就是將字符轉為位元組的過程與演算法

    • 解碼就是將位元組轉為字符的過程與演算法

  • 字符集 (字碼)

    • 各種文字及符號的總稱, 例如常見的有:

      • ASCII

      • GBK

      • Unicode

    • 以Unicode編碼為例, 其字碼為4~6個16進位數字, 並在前面加上U+

      • 英文字母A的Unicode字碼: U+0041

      • 歐元符號: U+20AC

  • 字符編碼

    • 將字符集轉為二進位

    • 例如ASCII字符編碼可將ASCII字符集中的128個字符轉為二進制

    • 代表字元的位元組會根據使用的編碼而定, 例如Unicode只定義了字符集以及每個字符對應到的唯一編碼值(code point), 編碼演算法則有UTF-8, UTF-16, UTF-32

    • 編碼是一種演算法, 可互相轉換字碼

      • 以A的位元組為例

        • UTF-8編碼: \x41

        • UTF-16LE編碼: \x41\x00

2.Python的操作

  • Python中的字串類型有兩種: str跟bytes, 也就是對應到前一個部分所說的字符轉為位元組(16進位),

    • python編輯界面和運行界面, 通常都是默認str為unicode編碼

    • unicode str的表示方式有兩種: u'字符串'或者'\u四位16進位數'. 它們是等價的, 而且都是str對象

    • 當bytes中的字節符合ASCII碼的可顯示字符時, 這個字節就會按照ASCII碼來顯示, 否則就會以16進位顯示

     >>> u'\x40\x41'
    u'@A'
  • 若要宣告的字串為bytes形式, 可以在字串前加上b

    >>> b'\x40\x41' 
    '@A'
  • str可以通過encode轉化为bytes, bytes可以通過decode轉化为str

    s = 'cafe'
    # str 'cafe'有四個unicode字元

    >>> b= s.encode('utf8')
    >>> b
    'cafe'
    # 用utf-8將str編碼成bytes

    >>> b.decode('utf8')
    u'cafe'
    # 用utf-8將bytes編碼成str
Previous6. encode/ decodeNext6.2.常見的編碼/ 解碼錯誤訊息與其意義

Last updated 5 years ago

Was this helpful?