Hi folks, I'm trying to calculate the amount of rent per lease for the life of the lease, by month. The following code provides the correct results except for the monthnum and billper. Monthnum is intended to show the month within the lease and the billper should list each date for rent billing.
For example, if the lease commences May 1, 2018 for a 60 month term, 2018-05-01 is monthnum = 1 and the billper = 2018-05-01. The following 59 rows needs to increment the monthnum and billper values by 1. The while loop (below) returns the first value correctly but stops without continuing through the rest of the True matches. Code (see below for results): 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 < duration: monthnum = billmocount billmocount += 1 billmo = perst while billmo < 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) Results: 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 Any help is appreciated! Thank you, Daryl _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor