Using “with open() as file” method, how to write more than once? [duplicate]

The w flag means “open for writing and truncate the file”; you’d probably want to open the file with the a flag which means “open the file for appending”. Also, it seems that you’re using Python 2. You shouldn’t be using the b flag, except in case when you’re writing binary as opposed to plain text content. In Python 3 your … Read more