title: While using Biopython: NameError: name 'pubmed_id' is not defined even though it has been previously defined?
body: <p>So I'm trying to retrieve some data from NCBI. The code I had previously written was rewritten by a much more experienced programmer, but it was not returning results in the format I wanted, so I made some modifications/additions:</p>
  
  <pre><code>for plant, disease in plant_disease_list:
      search_query = generate_search_query(plant, disease)
      handle1 = Entrez.esearch(db="pmc", term=search_query, retmax="10")
      record1 = Entrez.read(handle1)
      pubmed_ids = record1.get("IdList")
      if pubmed_id in pubmed_ids=="":
       print("Plant: {} Disease: {} PubmedID: DOI:".format(plant, disease))
      else:
  
       for pubmed_id in pubmed_ids:
         handle2 = Entrez.esummary(db="pmc", id=pubmed_id)
         records = Entrez.read(handle2)
         for record in records:
            doi = record.get("DOI")
            print("Plant: {} Disease: {} PubmedID: {} DOI: http://doi.org/{}".format(plant, disease, pubmed_id, doi))
  </code></pre>
  
  <p>where plant_disease_list is a previously defined list. The only problem is, with this code I get the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "scraperscript_python.py", line 28, in &lt;module&gt;
      if pubmed_id in pubmed_ids=="":
  NameError: name 'pubmed_id' is not defined
  </code></pre>
  
  <p>If I remove the if/else loop, and go back to the regular nested for loop, I don't get a syntax error, but the code doesn't print the data I want, i.e. it prints data for only those plant-disease pairs for which a PMID was found. Any idea on what I may be doing wrong?</p>