title: Python3 find last occurrence string then write
body: <p>I am trying to create a script that will add a zone to the end of named.conf if domain does not exist (last occurrence of the marker #--# and write to next line) . 
  I appear to be caught in a paradox of list vs. file object. If I open as list, I can find my string but cannot write to the file without closing list object first which is not a good solution.
  If I open the file as file object, I get an object error trying to use find</p>
  
  <pre><code>Traceback (most recent call last):
    File "named.py", line 10, in &lt;module&gt;
      answer = mylist.find('#--#')
  AttributeError: 'list' object has no attribute 'find'
  </code></pre>
  
  <p>or</p>
  
  <pre><code>  File "named.py", line 12, in &lt;module&gt;
      f.write("   zone \""+name+"\" {\n")
  io.UnsupportedOperation: not writable
  </code></pre>
  
  <p>What is the proper way to to open a file for search and editing in Python3?</p>
  
  <pre><code>import sys
  import string
  import os.path
  
  name = input("Enter the domain to configure zone for? ")
  #fd = open( "named.conf", 'w')
  if os.path.lexists("named.conf"):
          with open('named.conf') as f:
                  mylist = list(f)
                  print(mylist)
                  f.write("      zone \""+name+"\" {\n")
  </code></pre>