[Using Python 3.2]
If I do not pass the encoding
argument to open
, the file opens with locale.getpreferredencoding()
. So, for example, on my Windows machine, anytime I use open('abc.txt')
, it will be decoded using cp1252
.
I would like to switch all my input files to utf-8
. Obviously, I can add encoding = 'utf-8'
to all open
function calls. Or, better, encoding = MY_PROJECT_DEFAULT_ENCODING
, where the constant is somewhere defined globally.
But I was wondering if there is a clean way to avoid editing all my open
calls by changing the βstandardβ encoding. Is this something I can change by changing the locale? Or by changing a parameter within the locale? I tried to follow the Python manual, but did not understand how this is supposed to be used.
Thanks!
source share