[Tutor] File mode r+

Shitiz Bansal shitizb at yahoo.com
Sat Sep 24 10:11:58 CEST 2005


Hi,
I want to update a textfile using the r+ file mode.
contents of file:

abcd
efgh
ijkl
mnop
qrst
uvwx
yx12

my scripts is:

file1=open("aa.txt",'r+')
file1.readline()
file1.readline()
file1.write("1234\n")
file1.close()

This should replace the third line with 1234.
However it does nothing.

Moreover the script:

file1=open("aa.txt",'r+')
file1.write("1234\n")
file1.close()

does replace the first line with 1234.

could anyone explain what is happening?

shitiz

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Tutor mailing list