Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A awesome-python
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 13
    • Issues 13
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 317
    • Merge requests 317
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Vinta Chen
  • awesome-python
  • Merge requests
  • !280

Specify encoding explicitly

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/myd7349/master into master Dec 09, 2014
  • Overview 0
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: myd7349

Since the default system encoding of my Win7 x64(simplified Chinese) is not utf-8, but GBK; sort.py doesn't work in Python 3.4.2.

The traceback message is:

Traceback (most recent call last): File "E:\GitHub\sort.py", line 52, in main() File "E:\GitHub\sort.py", line 22, in main read_me = read_me_file.readlines() UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 6947: illegal multibyte sequence

So I just specify the encoding explicitly by passing the keyword argument 'encoding'. (Otherwise, Python 3.x will use the system's default encoding.)

The builtin 'open' function in Python 2.7.8 doesn't provide such a parameter, however. So I use codecs.open instead.

The modified version has already been tested on Win7 x64 with both Python 2.7.8 and Python 3.4.2.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/myd7349/master