Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle string/unicode escape during string encode #287

Open
acerv opened this issue Apr 4, 2019 · 1 comment
Open

Handle string/unicode escape during string encode #287

acerv opened this issue Apr 4, 2019 · 1 comment

Comments

@acerv
Copy link

acerv commented Apr 4, 2019

Hello everyone,

python2 differs from python3 when encoding a string with escape chars. For example:

# python2
my_str.encode('string-escape')
# python3
my_str.encode('unicode-escape')

It would be useful to handle the escape encoding in six, such as:

if PY2:
    encode_escape = 'string-escape'
else:
    encode_escape = 'unicode-escape'

Or a method that handle string encoding escape automatically.

Thanks in advice,
Andrea

@benjaminp
Copy link
Owner

In both versions, I believe you can simply use codecs.unicode_escape_(encode|decode).

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

No branches or pull requests

2 participants