Changes

Jump to: navigation, search

Python 3 String I/O

42 bytes added, 02:26, 4 October 2015
no edit summary
= String Handling and I/O =
Gramps (versions 4.0 to 4.1) 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 [http://docs.python.org/3/library/functions.html#open open()] in Python 3 is quite different from that of Python 2. Fortunately Python 2.7 provides [http://docs.python.org/2/library/io.html#io.open io.open()] 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 that does so. It's much easier to use only one encoding for all files. To ensure maximum portability we've selected '''UTF-8''' as that standard encoding.
[[Category:Developers/General]]
[[Category:GEPS|P]]

Navigation menu