title: Deleting Text in Parentheses in Python
body: <p>I have imported a <strong>csv</strong> file in <strong>Python</strong>. I'm trying to remove text present in parentheses in that file. </p>
  
  <p><em>I have written the following code:</em> </p>
  
  <pre><code>import csv
  
  
  with open('example.csv', 'r') as csv_file:
      csv_reader = csv.reader(csv_file)
  
  #for line in csv_reader:
      #print(line)
  
  
      def a(test_str):
          ret = ''
          skip1c = 0
          skip2c = 0
          for i in test_str:
              if i == '[':
                  skip1c += 1
              elif i == '(':
                  skip2c += 1
              elif i == ']' and skip1c &gt; 0:
                  skip1c -= 1
              elif i == ')' and skip2c &gt; 0:
                  skip2c -= 1
              elif skip1c == 0 and skip2c == 0:
                  ret += i
          return ret
  
          x = csv_reader
          x = a(x)
      for line in csv_reader:
          print(line)
  </code></pre>
  
  <p><em>Here are a couple of lines from my output:</em> </p>
  
  <pre><code>['CompanyA (CA)']
  ['CompanyB']
  ['CompanyC']
  ['CompanyD (CD)']
  ['CompanyE (CE)']
  </code></pre>
  
  <p>As you can see, the text in the parentheses is still there. The code doesn't seem to have worked on the file. </p>
  
  <p>I would like to remove the whole word between the parentheses. For instance, the output for "CompanyA (CA)" should only be <strong>CompanyA</strong>, not <strong>CompanyA CA</strong>. </p>
  
  <p><em>The following is an example from part of the code above, which does provide the expected result.</em></p>
  
  <pre><code>    def a(test_str):
  ret = ''
  skip1c = 0
  skip2c = 0
  for i in test_str:
      if i == '[':
          skip1c += 1
      elif i == '(':
          skip2c += 1
      elif i == ']' and skip1c &gt; 0:
          skip1c -= 1
      elif i == ')'and skip2c &gt; 0:
          skip2c -= 1
      elif skip1c == 0 and skip2c == 0:
          ret += i
  return ret
  
  x = "ewq[a [(b] ([c))]] This is a sentence. (once a day) [twice a day]"
  x = a(x)
  print x
  print repr(x)
  </code></pre>
  
  <p><em>Here is the output from that code</em>: </p>
  
  <pre><code>    ewq This is a sentence.  
  </code></pre>
  
  <p>Any help would be greatly appreciated. 
  Thank you for your time :)</p>