1

To reproduce problem:

In the PyScripter editor, write:

outf = open('output.txt', 'w')
outf.write('hello, world!')

Result:

For me at least, here is what happens, when output.txt does not already exist.

  1. output.txt is created
  2. output.txt will contain no data or text at all when opened by any text editor.

So my question is, how do I make this work?

Other information:

I am using PyScripter 2.5.3.0 x64, with Python 2.7.3, 64 bit as the interpreter.

Printing to the console works fine, all other functions and code work fine.

When I use python in Command Prompt, I can write to output files fine. My problem is only in PyScripter.

Thanks, DS

jsalonen
  • 29,593
  • 15
  • 91
  • 109
russell
  • 350
  • 1
  • 13
  • Have you tried appending `outf.close()`? – jsalonen Jun 18 '12 at 15:37
  • That solved my problem, thank you. When Python is run from command line, it makes no fuss when you forget to use outf.close()... it still works fine. So I had gotten used to forgetting it, I guess. – russell Jun 18 '12 at 15:47
  • Cool. I will provide you with complete answer nonetheless. – jsalonen Jun 18 '12 at 15:48

1 Answers1

0

The question was already resolved in comments, but I will post a complete answer regardless.

Writes to files may be delayed. To make sure they aren't, force a flush by closing the file:

outf.close()

If you don't want to explicitly call close, try using with ... as:

with open('output.txt', 'w') as outf:
    outf.write('hello, world!')
Community
  • 1
  • 1
jsalonen
  • 29,593
  • 15
  • 91
  • 109