Created
August 31, 2019 23:23
-
-
Save Xophe92/ed2ab8d6382c4daa330848424e5d3049 to your computer and use it in GitHub Desktop.
playing with encodings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
a = "Père Noël" | |
print(f"a = \"{a}\"") | |
print(f"type(a) => {type(a)} \n") | |
b = a.encode('utf-8') | |
print(f"b = {b}") | |
print(f"type(b) => {type(b)} \n") | |
print("{encoding} \t {b.decode(encoding)}") | |
for encoding in ['cp1252', 'utf-8']: | |
print(f"{encoding} \t\t {b.decode(encoding)}\n") | |
print("utf8 code sur 1 à 4 bytes de nombreux caractères") | |
c = b"\xe5\x81\x9a\xe6\x88\x8f\xe4\xb9\x8b\xe8\xaf\xb4" | |
print(c.decode('utf-8')) | |
""" | |
a = "Père Noël" | |
type(a) => <class 'str'> | |
b = b'P\xc3\xa8re No\xc3\xabl' | |
type(b) => <class 'bytes'> | |
{encoding} {b.decode(encoding)} | |
cp1252 Père Noël | |
utf-8 Père Noël | |
utf8 code sur 1 à 4 bytes de nombreux caractères | |
做戏之说 | |
Process finished with exit code 0 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment