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.

Files for read-source, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size read_source-0.0.2-py3-none-any.whl (1.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size read_source-0.0.2.tar.gz (1.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page