from time import sleep
with open('1.txt', 'wt') as f:
f.write('test_1')
sleep(15)
f.write('test_2')
open('1.txt', 'tw')
sleep(30)
with open('1.txt', 'tw') as f:
f.write('hacked')
print(f.read().decode('utf-8'))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 0: invalid continuation byte
str_ru = 'строка'
with open('__.txt', 'w') as f:
f.write(str_ru)
with open('__.txt', 'rb') as f:
print(f.read().decode('utf-8'))
str_ru = 'строка'
with open('__.txt', 'w') as f:
f.write(str_ru)
with open('__.txt', 'rb') as f:
print(f.read().decode('cp1251'))
with open('str_ru_text_1.txt', 'r', encoding='utf8') as f:
print(f.read())