Martin Panter added the comment:

If you only need the readable interface, use BytesIO or StringIO.

I once had an implementation like Serhiy’s, called dummywriter: 
<https://github.com/vadmium/python-lib/blob/99ec887/streams.py#L12>. To fully 
implement the writable file API it should also implement writable(), and 
write() should return the size of its argument.

Implementing this without opening a real file descriptor is slightly easier to 
manage (no need to worry about closing it, and no problem sharing instances or 
creating many copies). I don’t have a strong opinion about including it in the 
builtin library though, since it is pretty easy to implement the basics 
yourself.

I doubt anyone would need a readable and writable object, i.e. open(devnull, 
"r+"). On the other hand, it is occasionally useful to know how many bytes were 
written in total, so implementing tell() etc could be useful. (Linux’s 
/dev/null doesn’t work that way though; I find it always returns zero.)

----------
nosy: +martin.panter

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28864>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to