I'm currently trying to write data to a file and I heard you can save alot in file size by saving it in bytes. (Also to reduce lag on saving the file)
I'm currently using this for testing:
Syntax: Select all
from time import time
from paths import GAME_PATH
file_path = GAME_PATH / 'test.txt'
timestamp = time()
with open(file_path, 'wb') as file_stream:
test = ''
for i in range(100000):
test += '0|0|0|0|0\n'
file_stream.write(test.encode())
print(time() - timestamp)
When I do this, its still written in plain text and changes barely in size. Can you help and explain please?
Also is this the best way to save a file without having trouble with lag? Better to write everything at once, or write in several parts?