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.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com