On Fri, Jul 15, 2011 at 17:16, Dave Angel <d...@davea.name> wrote: > On 07/15/2011 07:39 PM, Richard D. Moores wrote:
>> with open("C:/test/test.txt", "a") as file_object: >> print("Hello, world!", file=file_object) >> >> Yes, that works for me with Windows Vista. However, if test.txt is >> empty, it puts in a blank line as line 1; line 2 is "Hello, world!". >> >> Dick >> _ > > I expect that your extra newline was already in the "empty" file. It cannot > have anything to do with using the forward slash for the filename. I see that you are correct. It seems that selecting all the text in a text file (in Notepad), then hitting the delete key doesn't guarantee that the file will be left truly blank. The way that consistently works for me is to place the cursor in the upper left corner of the file and hold down the delete key. Running with open("C:/test/test.txt", "w") as file_object: print(file=file_object) Also works. But that makes me wonder if there isn't a simpler way to do it with Python -- to delete the contents of a file without deleting the file? Dick _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor