title: How to fetch data from a text file using regex in python?
body: <p>I have a txt file, where I have lots of information, but I only want the ones which starts like this:</p>
  
  <pre><code>1. #BEGIN_DRUGCARD DB00001
  
  2. # Generic_Name:
  Lepirudin
  </code></pre>
  
  <p>I want to get in the first case what is starts with DB00001.
  In the second case, what is in the second line, then save both of them in to a text file.</p>
  
  <p>I have the following script, but it's not working, I get the following error:</p>
  
  <p>Traceback (most recent call last):
    File "/home/viki/workspace/prbb/drugnames", line 22, in 
      drug_id = line()
  TypeError: 'str' object is not callable
  Any ideas? </p>
  
  <pre><code>import re    
  
  regex1 = '#BEGIN_DRUGCARD '
  regex2 = '# Generic_Name:'
  
  x=y=0
  
  e = open ('drugbank.txt', 'r')
  f = open ('Drug_output.txt', 'w')
  
  for line in e.readlines():
  
      if re.match(regex1, line):
          y=1
          continue
  
      elif re.match(regex2, line):
          x=1
          continue
  
  if y==1:
      drug_id = line()
  
  if x==1:
      generic_name = line.split()
  
  f.write('drug_id')
  f.write('\n\n')
  f.write('generic_name')
  </code></pre>