Diff between opening files in 'r' and 'r+' mode

raghu vgvr620034 at gmail.com
Tue Jan 30 10:36:15 CET 2007

i want to know the difference between 'r' mode and 'r+' mode
1.i = open('c:\python25\integer.txt','w')-------->for writiing
  i.write('hai')--------->written some content in text file
  i = open('c:\python25\integer.txt','r')---->for reading
  print i.read()---->for printing the contents in that text file
  i = open('c:\python25\integer.txt','w')---------->for writing
  i.write('how')-----------?Rewrite the contents
  print i.read()
[MY QUESTION]:i want to read the text file contents cant it be done by 
giving (print i.read())?
Before going to next question [I deleted all the contents in the text 

2.i = open('c:\python25\integer.txt','r+')-----For reading and writing
   i.write('hai')--------->written some content  to text file
   print i.read()--------->{Ø
                               i write('')
                               print i.read()how')
                               i = open('c:\python25\integer.txt','r')
                               print i.read()
                               i = open('c:\python25\integer.txt','w')
                               i = open('c:\python25\integer.txt','r')
                              print i.read() } --->Thats what i saw on 
interpreter(In curly braces) when  i ran the script
[MY QUESTION]:1.from where the above in curly braces is printed?and i 
have written only 'hai' to the text file
                          2.Should i recall again the opening of the 
file in 'r' mode to read the file?

More information about the Python-list mailing list