title: How do I write only certain lines to a file in Python?
body: <p>I have a file that looks like this(have to put in code box so it resembles file):</p>
  
  <pre><code>text
  (starts with parentheses)
           tabbed info
  text
  (starts with parentheses)
           tabbed info
  
  ...repeat
  </code></pre>
  
  <p>I want to grab only "text" lines from the file(or every fourth line) and copy them to another file. This is the code I have, but it copies everything to the new file:</p>
  
  <pre><code>import sys
  
  def process_file(filename):
  
      output_file = open("data.txt", 'w')
  
      input_file = open(filename, "r")
      for line in input_file:
          line = line.strip()
                  if not line.startswith("(") or line.startswith(""):
                          output_file.write(line)        
      output_file.close()
  if __name__ == "__main__":
  process_file(sys.argv[1])
  </code></pre>