how to (re)set default file open() encoding for a whole python 3 script? -
python reads default file content encoding system. *
this s.o. question demonstrates behavior
i'd override globally, in script level. not want specify in every call "open()".
for example, if windows has cp1255 legacy codepage, i'd do:
magic_set_file_open_encoding('utf8') data = open('file').read() # contents assumed utf8
why silly:
- python3 "designed unicode". why's backward cowardliness?
- windows' system encoding legacy features, , not basis system of government.
- scripts' behavior unpredictable , whimsical.
you can override open file
open = functools.partial(open, encoding='utf8') open('somefile'): f#will *new open func* ...
Comments
Post a Comment