Python:计算值并发送emai

2024-10-03 23:27:02 发布

您现在位置:Python中文网/ 问答频道 /正文

更新:我已经更正了我的代码,下面的工作正常

基本上我需要一个输出如下邮件。 我做到了。但需要知道是否有任何有效的代码,然后低于一。你知道吗

名称5001 5010 9000 4%

名称5002 5010 9000 4%

名称5003 5010 9000 4%

名称5004 5010 9000 4%

  1. 在列表中存储值。你知道吗

下面是虚拟值

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))
  1. 将值列表分配给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

提前谢谢


Tags: 代码in名称列表forservercontainercount
1条回答
网友
1楼 · 发布于 2024-10-03 23:27:02

您的问题不清楚;代码示例没有任何意义。但从它的结构来看,似乎您正在尝试使用dict,但您正在定义或寻找列表。你知道吗

不知道为什么for server in servers,我希望您的服务器列表是数值的集合,这没有任何意义。你知道吗

请把清单和口述核对一下,然后列表.append()以及如何向字典中添加新的键、值对。你知道吗

相关问题 更多 >