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

Python2 unicode #1

Closed
mrichar1 opened this issue Jan 4, 2016 · 0 comments
Closed

Python2 unicode #1

mrichar1 opened this issue Jan 4, 2016 · 0 comments
Labels

Comments

@mrichar1
Copy link
Owner

mrichar1 commented Jan 4, 2016

This is an aide-memoire for some of the utf-8 related code for python2...

If we add £3.99 to the clipboard, then (with debugging turned on) we see the in-memory buffer holds:

python3: '£3.99' (we can walk away at this point...)

python2: '\xc2\xa33.99'

In both cases, the JSON history file will contain the 'ascii-fied' "\u00a33.99"

However, with python2 when the history file is read back in, it becomes:

python2 u'\xa33.99'

This causes the smart-update and duplicates code to fail, since these will be treated as unequal when compared.

The solution is to always try to decode('utf-8') the selection, ignoring any failures. This will ensure that all comparisons are of u'' objects.

The other solution of course is to just use python3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant