Skip to main content

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 -*-

Metadata

Release files for read-source 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for read-source 0.0.2
File Size Uploaded
read_source-0.0.2.tar.gz 1.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for read-source 0.0.2
File Interpreter ABI Platform
read_source-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 3.2 kB

Release files / read_source-0.0.2.tar.gz

Download URL read_source-0.0.2.tar.gz
Size 1.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1890960201eaa90ab1a94b65e7d450d66df5474970ff3bcb7460ed20ae9af889
BLAKE2b-256 checksum
How to use checksums
5f303973a0dc0cb622b3c7568691f50a9863eb7645a010c4a8712dde5be7b762
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.7.5 Windows/10

Release files / read_source-0.0.2-py3-none-any.whl

Download URL read_source-0.0.2-py3-none-any.whl
Size 1.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5465b27edb4c45502ce74f8adeb3fa374f507ce0b57016de187ad46f9cd3c24
BLAKE2b-256 checksum
How to use checksums
a4ffe1d00e14c4ef8f2b24f1e92ad4c17d33969eb09cec2590a442200015baa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.7.5 Windows/10

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page