<div>It was a little hard to follow your logic of your sample code (writing, reading and writing again), but <br>(1)The difference between r and r+.....<br>-  'r+' opens the file for both reading and writing.<br>-  'r' should be used when the file will only be read.
</div>
<div>
<p>I am not sure on how you want to store the contents of the file, but I have provided an example below. You could do something like this:<br>----------------------------------------------------------------------<br>fileContent = open(fname, 'r') 
</p>
<p>a = fileContent.readlines(); fileContent.close()<br><br>print a</p>
<p>----------------------------------------------------------------------</p>
<p>(2) If you are just going to read the file, then yes I would use just the 'r' argument.</p><br><br> </div>
<div><span class="gmail_quote">On 30 Jan 2007 01:36:15 -0800, <b class="gmail_sendername">raghu</b> <<a href="mailto:vgvr620034@gmail.com">vgvr620034@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">i want to know the difference between 'r' mode and 'r+' mode<br>1.i = open('c:\python25\integer.txt','w')-------->for writiing
<br>i.write('hai')--------->written some content in text file<br>i = open('c:\python25\integer.txt','r')---->for reading<br>print i.read()---->for printing the contents in that text file<br>
i = open('c:\python25\integer.txt','w')---------->for writing<br>i.write('how')-----------?Rewrite the contents<br>print i.read()<br>[MY QUESTION]:i want to read the text file contents cant it be done by
<br>giving (print i.read())?<br>Before going to next question [I deleted all the contents in the text<br>file]<br><br>2.i = open('c:\python25\integer.txt','r+')-----For reading and writing<br>  i.write('hai')--------->written some content  to text file
<br>  print i.read()--------->{؆('c:\python25\integer.txt','w')<br>                              i write('')<br>                              print i.read()how')<br>                              i = open('c:\python25\integer.txt','r')
<br>                              print i.read()<br>                              i = open('c:\python25\integer.txt','w')<br>                              i.write()<br>                              i = open('c:\python25\integer.txt','r')
<br>                             print i.read() } --->Thats what i saw on<br>interpreter(In curly braces) when  i ran the script<br>[MY QUESTION]:1.from where the above in curly braces is printed?and i<br>have written only 'hai' to the text file
<br>                         2.Should i recall again the opening of the<br>file in 'r' mode to read the file?<br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list
</a></blockquote></div><br>