title: UnsupportedOperation: not writable python
body: <pre><code> with open(r'G:\Programs\abc.txt') as f:
      for line in f:
            if line.startswith('logan'):
                   f.write('Johann Sebastian Bach')
                   print("Renewed line = ", line)
  </code></pre>
  
  <p>error message:</p>
  
  <pre><code>    runfile('G:/Python Programs/p17.py', wdir='G:/Python Programs')
  Traceback (most recent call last):
  
    File "&lt;ipython-input-2-393638b0e5ce&gt;", line 1, in &lt;module&gt;
      runfile('G:/Python Programs/p17.py', wdir='G:/Python Programs')
  
    File "G:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
      execfile(filename, namespace)
  
    File "G:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
      exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "G:/Python Programs/p17.py", line 11, in &lt;module&gt;
      khand.write('Johann Sebastian Bach')
  
  UnsupportedOperation: not writable
  </code></pre>
  
  <p>I have listed this code in python3.6 still I am getting an error message. I have required file in directory. Any suggestions? </p>