safest way to open files on all platforms
Fredrik Lundh
fredrik at pythonware.com
Mon Feb 14 09:46:11 EST 2005
"rbt" wrote:
> I'm using 'rb' in a situation where all files on the drive are opened. I'm not checking how the
> file is encoded before opening it (text, unicode, jpeg, etc.) That's why I though 'rb' would be
> safest.
if "safest way to open files" meant "safest way to open binary files", why
didn't you say so in your first post?
> Can 'U' be used with 'rb'? Should it be?
"U" is for text files, "b" is for binary files. binary files contain bytes, text
files contain text. if you're opening a file to read it as text (readline, read-
lines, iteration, etc), use "r" or "rU". if you're opening a file to read it as
binary bytes (read), use "rb".
</F>
More information about the Python-list
mailing list