Code: Select all
f = open("test.txt", "w")
f.write("testing\n")
f.close()Dave.
Code: Select all
f = open("test.txt", "w")
f.write("testing\n")
f.close()Code: Select all
hard /ram $ ./x.py
hard /ram $ cat test.txt
testing
hard /ram $ cat x.py
#!/usr/bin/env python
f = open("test.txt", "w")
f.write("testing\n")
f.close()
hard /ram $
Perhaps IDLE is creating the file in a different directory?davef21370 wrote:Okay, it works from the command line but not from within IDLE.
The proper script only needs to be run once to grab some info off t'internet and save it so I can live with the command line, but I'm still confused as to why it won't work from IDLE.
Dave.
I delete the file after each unsuccessful attempt and it reappears in the current directory when I retry the script. I have it running from the command line as we speak and all's well but no doubt this will rear it's ugly head again.joan wrote:Perhaps IDLE is creating the file in a different directory?
The only other things I can think of is a permissions problem. But if iDLE can create the file it should be able to write to it. Perhaps try a file flush in IDLE?davef21370 wrote:I delete the file after each unsuccessful attempt and it reappears in the current directory when I retry the script. I have it running from the command line as we speak and all's well but no doubt this will rear it's ugly head again.joan wrote:Perhaps IDLE is creating the file in a different directory?
Thanks anyway.
Dave.
Code: Select all
with open("test.txt", "w") as f:
f.write("testing\n")Not in a position to try that at the moment as my Pi is tied up trying to save the feelings of cattle (may post more details on that depending on the outcome) but will try as soon as and update accordingly.elParaguayo wrote:Does it make any difference if you use the 'with' context formatting, i.e.Code: Select all
with open("test.txt", "w") as f: f.write("testing\n")
I do most of my coding on the Pi and find IDLE quick and easy. The bit of C I write is done using Geany which I find sluggish and awkward.paddyg wrote:I've come across other things (perfectly good python) that don't work with IDLE. Is there any good reason why you would persist in using it?
Kind of avoiding animals too much suffering.paddyg wrote:'save' as in record the feelings or as in avoid hurting the feelings. Please tell us more, whatever the results.