我有一种情况,我必须遍历列表,从文件中获取信息,写入新文件,发送电子邮件,然后返回到下一个列表迭代重新开始过程。
我会尝试写出来,然后把我的代码在你看看。
该列表是ipaddresses的列表,并且这两个文件都是文本。在第一次比较循环后调用列表中的下一次迭代
DEF从文件1
抓住信息DEF建立我的列表1(第一个代码块)
DEF采取list1的[0]其应用到file1和建造从中文件2(第二个代码块)
高清从中获取电子邮件地址list1的[0]
高清发送电子邮件与文件2
(我能做到这一切,它只是又回到了列表1 [1],我不能这样做)
去LIST1 [1]适用于file1中建立文件2发送电子邮件等...直至列表结束
2 import re
3
4 def one_ip_each():
5 one_ip_each = []
6 global ipAddr
7 with open('Invalid_names_file') as Invalid_names_file:
8 a = [re.search(r'((\d+\.)+\d+)', line).group() for line in \
9 Invalid_names_file]
10 for x in a:
11 if x not in one_ip_each:
12 one_ip_each.append(x)
13 ipAddr = x
14 return ipAddr
15 ## makes an iterator that interpreter can step through, yet other funciton
16 ## complains that it's not a string
17 # ipAddr = iter(one_ip_each)
18 # return ipAddr
19
20 one_ip_each()
这里的代码,返回我想要的东西(不IPADDR作为一个国际热核实验堆),而不是循环)
5 def isp_email_names():
6 with open('Invalid_names_file') as Invalid_names_file:
7 with open('ISP_names_file', 'w') as ISP_names_file:
8 for line in Invalid_names_file:
9 if one_ip_each.ipAddr in line:
10 ISP_names_file.write(str(line))
11 ISP_names_file.flush()
了行号,这将帮助一些
希望。
我使ipAddr成为一个全球性的,所以我可以从电子邮件功能调用它来知道file2会去适当的人。
我不知道这件事是否重要。
,如果我让IPADDR到ITER(如线17和18),我得到 - >
TypeError: 'in <string>' requires string as left operand, not list_iterator
我喜欢学习,而我看,但我很坚持。指出我在正确的方向,我会阅读并回来回答这个问题。
还有我读过的人想要构建过滤器,def更多的功能。
我会认为它应该很容易,我只是无法把握它。
(职位是那种长,但想成为thourough)
格式的代码和文本,或者没有人愿意提供帮助。 –