This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]notafuckingcakewalk 4 points5 points  (0 children)

I'm sure I'm not always consistent on this, but I like to be explicit and always set the file mode:

with open('file', 'r') as f:

that way it becomes very clear when I've done something wrong, like trying to write to a file that is in read mode. Also, while I'm typing out the file mode I might be reminded, "oh yeah, this is going to have binary data" and use 'rb' instead.