python - Python:计算值并发送电子邮件
问题描述
更新:我已经更正了我的代码,下面的工作正常
基本上我需要像下面这样的邮件输出。我做到了这一点。但需要知道是否有任何有效的代码然后低于一个。
名称 5001 5010 9000 4 %
名称 5002 5010 9000 4 %
名称 5003 5010 9000 4 %
名称 5004 5010 9000 4 %
- 将值存储在列表中。
以下是虚拟值
container = []
for server in range(1,5):
container.append('name')
container.append(server + 5000)
container.append(5000+10)
container.append(4000+5000)
container.append(2500 % 12)
print('\n' + str(container))
- 将值列表分配给 msgBody 以便通过电子邮件发送
我只是在这里放一段代码。下面也工作正常
msgBody1 = ''
对于范围内的计数(4):
if count == 0:
tempValue = '\n' + '\n' + str(container[count]) + '\t' + str(container[count+1]) + '\t' + str(container[count+2]) + '\t'
+ str(container[count+3]) + '\t' + str(container[count+4])
msgBody1 = msgBody1 + str(tempValue) + ' %'
elif count == 1:
tempValue = '\n' + '\n' + str(container[count+4]) + '\t' + str(container[count+5]) + '\t' + str(container[count+6]) + '\t'
+ str(container[count+7]) + '\t' + str(container[count+8])
msgBody1 = msgBody1 + str(tempValue) + ' %'
elif count == 2:
tempValue = '\n' + '\n' + str(container[count+8]) + '\t' + str(container[count+9]) + '\t' + str(container[count+10]) + '\t'
+ str(container[count+11]) + '\t' + str(container[count+12])
msgBody1 = msgBody1 + str(tempValue) + ' %'
elif count == 3:
tempValue = '\n' + '\n' + str(container[count+12]) + '\t' + str(container[count+13]) + '\t' + str(container[count+14]) + '\t'
+ str(container[count+15]) + '\t' + str(container[count+16])
msgBody1 = msgBody1 + str(tempValue) + ' %'
任何其他更好和更短的代码来替换 msgBody1
提前致谢
解决方案
你的问题不清楚;代码示例没有任何意义。但是从它的结构来看,您似乎正在尝试使用 dict,但您正在定义或采购列表。
不知道为什么for server in servers
,我希望你的服务器列表是数值的集合,这没有任何意义。
请仔细阅读 list Vs dict 和 list.append() 以及如何将新的键、值对添加到字典中。
推荐阅读
- php - 使用 PDO 加载数据时出现问题:编码错误
- android - 如何从android studio向服务器发送删除请求?
- javascript - 托管我的网站后如何使用 php 重定向到另一个页面
- python - 使用 Selenium 使用 get_elements_by_xpath 在循环中单击每个按钮后获取页面源
- python - Numpy搜索数组中的元素(分散和减少)
- css - MaterialUI Box 接管背景图片
- javascript - 为什么audio src上调用的timeupdate事件会改变HTML/JS
- java - 如何配置 gradle(使用 kotlin dsl)在 Java 之前编译 Scala?
- sql - 按不同时间间隔获取汇总结果
- sql-server - 聚集索引顺序