title: Python individual rows for each month's rent in term
body: <p>I'm stuck on one piece of Python code.</p>
  
  <p>From an XML file, we're parsing data successfully in the following code, excluding the while loops and associated variables.  We need to load a table into SQL with the entire rent schedule, by month, for the life of the lease.  Rent is always billed on the first of the month but the amount escalates at different times with different amounts depending on the lease.  The objective is to return one row per billing month with the date of each months' rent to be billed (YYYY-MM-DD).  If the lease is for 60 months and there is a rent escalation in the 25th month, we'll need to show 60 rows with the amount repeating 24 times for the first two years and 36 times for the remainder.  The scenario needs to be flexible to adapt to annual increases for some, and a few other variable conditions.  </p>
  
  <p>Can someone point out where I've gone wrong in my While Loop to get the desired results?</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  import pyodbc
  import dateutil.relativedelta as rd
  import dateutil.parser as pr
  
  
  tree = ET.parse('DealData.xml')
  root = tree.getroot()
  
      for deal in root.findall("Deals"):
          for dl in deal.findall("Deal"):
              dealid = dl.get("DealID")
              for dts in dl.findall("DealTerms/DealTerm"):
                  dtid = dts.get("ID")
                  dstart = pr.parse(dts.find("CommencementDate").text)
                  dterm = dts.find("LeaseTerm").text
                  darea = dts.find("RentableArea").text
              for brrent in dts.findall("BaseRents/BaseRent"):
                  brid = brrent.get("ID")
                  begmo = int(brrent.find("BeginIn").text)
                  if brrent.find("Duration").text is not None:
                      duration = int(brrent.find("Duration").text)
                  else:
                      duration = 0
                  brentamt = brrent.find("Rent").text
                  brper = brrent.find("Period").text
                  perst = dstart + rd.relativedelta(months=begmo-1)
                  perend = perst + rd.relativedelta(months=duration-1)
                  billmocount = begmo
                  while billmocount &lt; duration:
                      monthnum = billmocount
                      billmocount += 1
                  billmo = perst
                  while billmo &lt; perend:
                      billper = billmo
                      billmo += rd.relativedelta(months=1)
  
                  if dealid == "706880":
                      print(dealid, dtid, brid, begmo, dstart, dterm, darea, brentamt, brper, duration, perst, perend, \
                      monthnum, billper)
  </code></pre>
  
  <p>The results I'm getting look like this:</p>
  
  <pre><code>706880 4278580 45937180 1 2018-01-01 00:00:00 60 6200 15.0 rsf/year 36 2018-01-01 00:00:00 2020-12-01 00:00:00 35 2020-11-01 00:00:00
  706880 4278580 45937181 37 2018-01-01 00:00:00 60 6200 18.0 rsf/year 24 2021-01-01 00:00:00 2022-12-01 00:00:00 35 2022-11-01 00:00:00
  </code></pre>