Python 3 String I/O  From Gramps Jump to: navigation, search
String Handling and I/O  Gramps must be able to run correctly in
both Python 2.7 and Python 3.x. Unlike Python 2, Python 3
encodes the characters of all strings in UTF-16 and
automatically transcodes all string I/O. With default settings
this will frequently raise UnicodeErrors, therefore all string
I/O must be coded carefully. Moreover, the builtin open() in
Python 3 is quite different from that of Python 2. Fortunately
Python 2.7 provides which is the same, and Python 3 provides an
alias to that function, enabling compatible code. Binary file
I/O on a file opened in text mode will fail in Python 3 because
of the automatic transcoding.  There are several default
encodings which may apply to I/O functions unless an encoding is
specified, depending upon the encoding of the locale used to
start Python and calling locale.setlocale() has no effect upon
these defaults. The encoding used to write files is not recorded
in the file unless you include code