[Tutor] Can't edit a file I've opened with open(), then closed with close()

Richard D. Moores rdmoores at gmail.com
Mon Sep 12 07:29:30 CEST 2011

Win 7, Python 3.2.1

I'm trying to improve my skills with opening text files, reading from them,
and writing to them.

But while I'm doing this sometimes I want to manually modify the text file
I'm using, C:\t\text.txt . Say I've done this:

>>> f = open(r"C:\t\test.txt", 'r+')
>>> f.read()
'0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19Now is
the time for all goo men\nto come to the aid\nof their party.\n'
>>> f.close()

and I decide to manually delete all those integers, and also correct "goo".
So I open test.txt and do that. But when I try to save, I get "The process
cannot access the file because it is being used by another process." I'm
using IDLE, so I close it. But still no save. Why? And what can I do about
it? I check with the task manager and see 22 pythonw.exe processes..


Dick Moores
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110911/bf26b96c/attachment-0001.html>

More information about the Tutor mailing list