if key == this_week and new_dict[team][url][this_week] and new_dict[team][url][last_week] : diff = float(new_dict[team][url][this_week]["50.0"]) \ - float(new_dict[team][url][last_week]["50.0"]) new_dict[team][url][key].update({"diff" : diff }) rt = {"test": new_dict} print(new_dict) output = template.render(rt) with open('../index.html', 'w') as f: f.write(output); with open('../index.html') as fp: msg = EmailMessage() msg.set_content(fp.read(),'html') msg['Subject'] = '%s - weekly response_time report' % sys.argv[1].upper() msg['From'] = '*****@*****.**' msg['To'] = "*****@*****.**" # Send the message via our own SMTP server. s = smtplib.SMTP('localhost') s.send_message(msg) s.quit() print("end")