[Tutor] Simultaneous read and write on file

Cameron Simpson cs at zip.com.au
Mon Jan 18 22:57:22 EST 2016


On 18Jan2016 22:29, Peter Otten <__peter__ at web.de> wrote:
>Anshu Kumar wrote:
>> I have read in documentation that wb+ mode is for writing and reading. Am
>> i using wrong mode, should i use rb+ ?
>
>Quoting https://docs.python.org/2.7/library/functions.html#open
>"""
>note that 'w+' truncates the file.
>"""
>That's why you lose the file's current content, and, yes, "r+b" would avoid
>that.

And I stand corrected; I should have paid more attention. Thanks!

Cheers,
Cameron Simpson <cs at zip.com.au>


More information about the Tutor mailing list