[Tutor] Diff between opening files in 'r' and 'r+' mode

vanam vgvr620034 at gmail.com
Tue Jan 30 06:42:28 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 file]

2.i = open('c:\python25\integer.txt','r+')-----For reading and writing
   i.write('hai')--------->written some content  to text file
   print i.read()--------->{Ø
†('c:\python25\integer.txt','w')
                               i write('')
                               print i.read()how')
                               i = open('c:\python25\integer.txt','r')
                               print i.read()
                               i = open('c:\python25\integer.txt','w')
                               i.write()
                               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?

-- 

                                           Vanam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070130/446175a4/attachment.htm 


More information about the Tutor mailing list