open() mode args

M

mpnordland

What is the correct file mode to pass to open() when I want to both read
and write on the open file?
 
S

Steven D'Aprano

What is the correct file mode to pass to open() when I want to both read
and write on the open file?

open("filename", "r+") for text mode, "r+b" for binary mode. If your
operating system does not distinguish between the two, you can use either.

More detail is available in the Fine Manual, or in the interactive help:

help(open)

at the Python prompt.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top