[Python-Dev] IO module precisions and exception hierarchy (original) (raw)
MRAB python at mrabarnett.plus.com
Sun Sep 27 17:14:35 CEST 2009
- Previous message: [Python-Dev] IO module precisions and exception hierarchy
- Next message: [Python-Dev] IO module precisions and exception hierarchy
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Pascal Chambon wrote:
Found in current io PEP : Q: Do we want to mandate in the specification that switching between reading and writing on a read-write object implies a .flush()? Or is that an implementation convenience that users should not rely on? -> it seems that the only important matter is : file pointer positions and bytes/characters read should always be the ones that the user expects, as if there were no buffering. So flushing or not may stay a non-mandatory behaviour, as long as the buffered streams ensures this data integrity. Eg. If a user opens a file in r/w mode, writes two bytes in it (which stay buffered), and then reads 2 bytes, the two bytes read should be those on range [2:4] of course, even though the file pointer would, due to python buffering, still be at index 0.
+1
Q from me : What happens in read/write text files, when overwriting a three-bytes character with a single-byte character ? Or at the contrary, when a single chinese character overrides 3 ASCII characters in an UTF8 file ? Is there any system designed to avoid this data corruption ? Or should TextIO classes forbid read+write streams ?
If the characters are always the same number of bytes) then overwriting could be possible; that would, however, make the behaviour more complicated (sometimes you can, sometimes you can't), so it's probably just simpler to forbid read+write text streams.
- Previous message: [Python-Dev] IO module precisions and exception hierarchy
- Next message: [Python-Dev] IO module precisions and exception hierarchy
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]