read write mode python
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1466000/python-open-built-in-function-difference-between-modes-a-a-w-w-and-r">python open built-in function: difference between modes a, a+, w, w+, and r+?</a>  </p>
</blockquote>



<pre><code>try:
    f = open("file.txt", "r")
    try:
        string = f.read()
        line = f.readline()
        lines = f.readlines()
    finally:
        f.close()
except IOError:
    pass


try:
    f = open("file.txt", "w")
    try:
        f.write('blah') # Write a string to a file
        f.writelines(lines) # Write a sequence of strings to a file
    finally:
        f.close()
except IOError:
    pass
</code></pre>

<p>Hi,</p>

<p>this is mode which i can read and write file but i want to open file once and perform both read and write operation in python</p>
