Created
July 16, 2015 17:40
-
-
Save rafaelgotts/9826b02dc99ff5da6ee2 to your computer and use it in GitHub Desktop.
Exemplo de decodes para windows usando python
This file contains hidden or 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: utf-8 | |
| # print_textos.py | |
| import sys | |
| # Aqui eu converto do utf-8 para unicode e depois para latin1 ou cp850 | |
| # Se fizer direto, ele tentará usar a tabela ascii e dai... | |
| texto = "Olá code page 1252!".decode("utf-8").encode('latin1') | |
| texto2 = "Olá code page 850!".decode("utf-8").encode('cp850') | |
| # Print comum | |
| print texto | |
| print texto2 | |
| print '--------------' | |
| # Usando stdout | |
| sys.stdout.write(texto + "\n") | |
| sys.stdout.write(texto2 + "\n") | |
| sys.stdout.flush() | |
| sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment