Skip to main content

No project description provided

Project description

Read Python3 Source File With Correct Encoding

according to https://www.python.org/dev/peps/pep-0263/, python3 source file encoding are default to be utf-8.

But open()'s encoding will be gbk on windows, So don't use open without encoding to read a python3 source file.

example:

from read_source import get_encoding, read
print(get_encoding('tests/source/gb18030/dash-star-dash.py')) # gb18030
with read('tests/source/gb18030/dash-star-dash.py') as f:
    print(f.read()) 
    # -*- coding: gb18030 -*-

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

read_source-0.0.2.tar.gz (1.5 kB view hashes)

Uploaded Source

Built Distribution

read_source-0.0.2-py3-none-any.whl (1.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page