Home python why does not work output to the file?

why does not work output to the file?

Author

Date

Category

does not work output in Output.txt, IDE gives an error

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

Code:

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' & lt; = dnk [i] & lt; = '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)

Answer 1, Authority 100%

You need to explicitly specify that you open the file to write:

with open ('output.txt', 'w') as ouf:
  OUF.WRITE (RESULT)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions