[Python-Dev] The path module PEP
Ian Bicking
ianb at colorstudy.com
Tue Jan 24 22:58:36 CET 2006
BJörn Lindqvist wrote:
> * Functions for reading and writing a whole file - better handled
> by file objects read() and write() methods.
I would be disappointed to see this left out, because I get really tired
of this little dance:
f = open(filename)
c = f.read()
f.close()
return c
Then you can put a try:finally: in there too for extra correctness.
Anyway, I write this code all the time, and it's really tiresome.
open(filename).read() also works, but relies on Python's reference
counting to be really reliable; maybe I shouldn't worry about that and
use just that form. But that bothers me too. The same occurs during
writing.
The original Path object has a bytes and text method (I think), which
nicely distinguishes between the two cases. This helps suggest better
and more explicit handling of unicode, something that Python should work
harder at making clear.
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Python-Dev
mailing list