【发布时间】:2019-02-28 15:40:31
【问题描述】:
更新:我已经更正了我的代码,下面的代码可以正常工作
基本上我需要像下面这样的邮件输出。 我做到了这一点。但需要知道是否有任何有效的代码然后低于一个。
名称 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
提前致谢
【问题讨论】:
-
看起来您将整数索引与列表(必须是数字)和字典混合在一起。
server是什么?一个号码?细绳?请提供示例输入。但基本上这是失败的,因为最初程序正在尝试访问a[0](因为 count==0),而a是一个空列表。
标签: python python-3.x python-2.7 python-requests