Welcome to chinese_to_english_punctuation Documentation
chinese_to_english_punctuation rewrites Chinese full-width punctuation into its English half-width equivalent, and fixes the spacing around it. Documents written by Chinese speakers about technical topics almost always end up mixing the two: the narrative uses ,。:;?!()【】《》“” while the technical terms stay in English. That mix reads poorly in Markdown and reStructuredText, and it breaks tooling that expects ASCII punctuation. This library converts , to ,, 。 to ., () to (), 【】 and [] to [], 《》 and 〈〉 to <> and so on, inserts the single space that belongs between a Chinese character and an adjacent Latin word or number, and leaves everything else alone.
The conversion is line-oriented and deliberately conservative about structure. Leading indentation is preserved verbatim, so fenced code blocks, .. code-block directives and nested list continuations survive untouched. Runs of two or three identical marks (。。。, ???, !!!) are treated as a single unit rather than being split apart. Spaces that would otherwise be introduced just inside paired Markdown markers such as **bold** are cleaned up afterwards.
The public Python API is a single function, process, which takes text and returns text. The same behavior is available from the command line through c2ep, which offers c2ep text for reading from --text or stdin and writing to stdout, and c2ep file for rewriting a UTF-8 file in place. Files that are not valid UTF-8 are rejected rather than guessed at, and --dry_run reports what would change without touching anything.
Usage:
from chinese_to_english_punctuation.api import process
process("这是Python代码,它使用Flask框架。")
# '这是 Python 代码, 它使用 Flask 框架.'
$ c2ep text --text "这是Python代码,它使用Flask框架。"
这是 Python 代码, 它使用 Flask 框架.
$ c2ep file --path ./README.md --dry_run
./README.md: 12 line(s) would change (dry run, nothing written)
$ c2ep file --path ./README.md
./README.md: 12 line(s) changed
Install
chinese_to_english_punctuation is released on PyPI, so all you need is to:
$ pip install chinese-to-english-punctuation
To upgrade to latest version:
$ pip install --upgrade chinese-to-english-punctuation
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chinese_to_english_punctuation-0.1.2.tar.gz.
File metadata
- Download URL: chinese_to_english_punctuation-0.1.2.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01d83c2f009d0d3fce0e8d4d2306cd9a0114f7c1caacf560e3ae9b93c05a29b4
|
|
| MD5 |
3b89761d8e6aa67f0383bc9be57d520a
|
|
| BLAKE2b-256 |
cf7fd863a864082563068d57b8b46374f89b95adab395f642f29b81fe6609c3d
|
File details
Details for the file chinese_to_english_punctuation-0.1.2-py3-none-any.whl.
File metadata
- Download URL: chinese_to_english_punctuation-0.1.2-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbf9421de4107c8d70fa288a9684cfa2d4657f53e73ac27baf50120919a30a89
|
|
| MD5 |
7f1a604554451b5b49ff59c1a9a91e71
|
|
| BLAKE2b-256 |
83c55971026fde77087d6e84ad319088dd99ad60d5350b04a1cd3bf26f71d52b
|