[Python-Dev] Proposal for new core module: UserFIle

Keith Dart kdart at kdart.com
Thu Dec 11 17:37:04 EST 2003

On Thu, 2003-12-11 at 14:24, Skip Montanaro wrote:
>     Keith> class TextFile(UserFile):
>     Keith>      """TextFile(self, name, mode="r", bufsize=-1, linesep=None)
>     Keith> A file object that handles different line separator
>     Keith> conventions. This file object's readline() method returns the
>     Keith> line with trailing line separator stripped, and raises EOFError
>     Keith> on end of file. The writelines() method will append an
>     Keith> appropriate line separator when writing. Thus, this file object
>     Keith> allows reading and writeing non-native text files.
>     Keith>      """
> Is there a reason the universal newline mode doesn't cover this case
> already?

This module lets you explicitly create a text data file for any
platform. The universal newline feature of python is for Python modules
only, and lets you transparently import and exec Python source files
with the different line ending formats. That is a different thing. 

>     Keith>      """MergedIO(outfile, infile)
>     Keith> Combines a write stream and a read stream into one read/write
>     Keith> object.""" 
> And isn't this subsumed by mode='r+'?

No, mode r+ lets you create a _single_ file descriptor that is in
read-write mode. The MergedIO lets you take who file objects (with
different file descriptors), one readable the other writable, and
combine them at the method-call level into one read-write object. This
is useful for pipes, or when you get file objects from libraries. 

-- ------------------------------------------------------------------------- 
Keith Dart
<mailto:kdart at kdart.com>
Public key ID: B08B9D2C Public key: <http://www.kdart.com/~kdart/public.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-dev/attachments/20031211/92d5c829/attachment.bin

More information about the Python-Dev mailing list