-1

I am try to make it possible to save progress in my python game put the following line is giving me problems:

dataW = open("data.dat","wb")

How can I stop this line from clearing my file.

Crafterguy
  • 171
  • 5
  • 1
    From the [`open()` documentation](https://docs.python.org/2/library/functions.html#open): *The most commonly-used values of mode are 'r' for reading, 'w' for writing (**truncating the file if it already exists**), and 'a' for appending*. Bold emphasis mine. – Martijn Pieters Jul 21 '16 at 19:44

1 Answers1

0

You're opening the file in write mode:

'w' for only writing (an existing file with the same name will be erased)

Emphasis mine

You meant to use the append mode:

'a' opens the file for appending

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139