Skip to content

Add encoding parameter for non-ASCII characters#17

Open
kuihao wants to merge 1 commit intoremykarem:masterfrom
kuihao:master
Open

Add encoding parameter for non-ASCII characters#17
kuihao wants to merge 1 commit intoremykarem:masterfrom
kuihao:master

Conversation

@kuihao
Copy link
Copy Markdown

@kuihao kuihao commented Mar 18, 2024

Description

Fixed the UnicodeDecodeError issue in p2j when processing Python scripts with Chinese comments. Added an encoding parameter (default=“utf-8”) to handle character encoding. Resolves Issue #16.

Usage

Run code (OS is windows 11):

p2j .\code.py -e "Big5" # Specify the desired encoding (e.g., Big5)

Expected output:

Notebook .\code.ipynb written.

Fixed the `UnicodeDecodeError` issue in `p2j` when processing Python
scripts with Chinese comments. Added an encoding parameter
(default=“utf-8”) to handle character encoding. Resolves Issue remykarem#16.
Copy link
Copy Markdown
Owner

@remykarem remykarem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kuihao

Firstly, sorry for the late reply!

Secondly, thank you for taking the time to create a PR.

I've left a comment and it's a small change to expose this new feature in the CLI.

Thanks!

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args.encoding should be passed to the encoding parameter that we're exposing in the functions jupyter2python and python2jupyter.

i.e.

if args.reverse:
  jupyter2python(
    ...,
    encoding=args.encoding
  )
else:
  python2jupyter(
    ...,
    encoding=args.encoding
  )

Otherwise, the value of the encoding parsed from the CLI won't enjoy this new feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants