Last active
August 29, 2015 14:01
-
-
Save felipe-prenholato/bdf3aacfcd2924b90410 to your computer and use it in GitHub Desktop.
Python locale use sample
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
| $ LC_ALL='es_MX.UTF-8' python foo.py | |
| {'Default locale': ('es_MX', 'UTF-8'), 'Default locale data': ''} | |
| {'Current locale data': '', 'Current locale': (None, None)} | |
| {'Default locale': ('es_MX', 'UTF-8'), | |
| 'New locale': ('pt_BR', 'UTF-8'), | |
| 'New locale data': 'BRL '} | |
| {'Current locale data': 'MXN ', 'Current locale': ('es_MX', 'UTF-8')} |
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
| # You must have pt_BR locale generated on yourt system (man locale-gen) | |
| import locale | |
| from pprint import pprint | |
| pprint({"Default locale": locale.getdefaultlocale(), "Default locale data": locale.localeconv()['int_curr_symbol']}) | |
| print("") | |
| print({"Current locale": locale.getlocale(), "Current locale data": locale.localeconv()['int_curr_symbol']}) | |
| print("") | |
| def set_locale(): | |
| locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8') | |
| pprint({"New locale": locale.getlocale(), | |
| "Default locale": locale.getdefaultlocale(), | |
| "New locale data": locale.localeconv()['int_curr_symbol']}) | |
| print("") | |
| locale.resetlocale() | |
| set_locale() | |
| print({"Current locale": locale.getlocale(), "Current locale data": locale.localeconv()['int_curr_symbol']}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment