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

Keith Dart kdart at kdart.com
Thu Dec 11 19:04:45 EST 2003

On Thu, 2003-12-11 at 15:00, Guido van Rossum wrote:

> I also note that you change the meaning of readline() to return the
> line with the trailing separator stripped, and raise EOFError when you
> have reached the end.  That's a big deviation from the standard file
> semantics, and shouldn't be done lightly in a subclass (it means that
> a TextFile instance is not substitutable for a regular file instance
> in most cases).

Yes, that is true, but I have had to use that semantic in other places
(usually when using non-blocking sockets) and I personally prefer it.
But as others have pointed out this functionality is not needed in
Python 2.3 and so I will drop it.  

> Reviewing the rest of UserFile, I see several possibly useful
> additions (locking, fstat() etc.) and one semantic change that
> deserves to be a separate subclass or mix-in (the EINTR behavior).

> And nothing that warrants the name "UserFile" (in fact, all the
> other UserXXX classes are specifically *not* subclasses of the native
> XXX class).

Yes, a lot of extra stuff was added later. Perhaps some should be
factored out into a new module. Perhaps "filelib"? It was just more
consistent for me, since I also have UserInt, UserFloat, and UserLong
modules as well. But those are, thankfully, no longer needed either.

> > 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.
> It looks like you are simply making all write operations go to the
> writable object and all the read operations go to the readable object.
> That's not a very sophisticated notion of "merging", and I'm not sure
> what the point is.  Perhaps some examples of how you use this would
> help.

A quick example:

import os
import UserFile

r, w = os.pipe()
rf = os.fdopen(r)
wf = os.fdopen(w)

fo = UserFile.MergedIO(rf, wf)


rwio = UserFile.MergedIO(sys.stdin, sys.stdout)

Perhaps "merged" is not the right word. It is not intended to merge
files, but combine a separate read file object and write file object
into one object that can be passed to other library methods that want a
single read/write object (such as my "expect" module...) 

> I note that in general your proposals are low on motivation, which is
> going to do a lot of damage to your case if you don't fix this soon.
> You may be underestimating the level of motivation needed to get
> features added to the stdlib -- it's "batteries included" but also (to
> some extent) "TOOWTDI".

Hm, ok. more use cases? What I have submitted, and will submit, exist
because I did need them for real work at some point, and have found them
to be re-usable.

-- ------------------------------------------------------------------------- 
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/912b733d/attachment-0001.bin

More information about the Python-Dev mailing list