4

Не работает вывод в output.txt, IDE выдает ошибку

ouf.write(result) io.UnsupportedOperation: not writable

Код:

with open('dataset_3363_2.txt') as inf:
    dnk = inf.readline()

result = ''
i = 0
kol = 0
let = ''
while i != (len(dnk) - 1):
    if not ('0' <= dnk[i] <= '9'):
        for j in range(0, kol):
            result += let
        let = dnk[i]
        kol = 0
    else:
        buf = str(kol) + dnk[i]
        kol = int(buf)
    i += 1
for i in range(0, kol):
            result += let

with open('output.txt') as ouf:
    ouf.write(result)

1 ответ 1

8

Тебе нужно явно указать, что ты открываешь файл для записи:

with open('output.txt', 'w') as ouf:
    ouf.write(result)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.