0

Everytime I set this variable, the exported txt file is instantly deleted.

OutFile1 = open('C:/Saves/Popventure/Save1.txt', 'wt')

As soon as the console reads this code, the txt is empty. I've tested, and turns out it is this exact line that causes the issue. How do I stop the code from activating, or deleting what's inside the txt?

Pop Car
  • 363
  • 5
  • 15

2 Answers2

1

Read these carefully: https://stackoverflow.com/a/1466036/1453822 and https://stackoverflow.com/a/1466037/1453822

By using the w mode you tell Python to truncate the file if it exists.

Community
  • 1
  • 1
DeepSpace
  • 78,697
  • 11
  • 109
  • 154
0

If you check the official docummentation 'w' means

open for writing, truncating the file first

If you want to keep a current content you can open file in the append mode:

open('/path/to/file', 'at')

it means

open for writing, appending to the end of the file if it exists

zero323
  • 322,348
  • 103
  • 959
  • 935