call next iteration in list after first comparision loop
<p>i have a situation where i have to loop over a list, grab info from a file, write a new file, send an email, and then go back to the list for the next iteration to start the process over again.<br>
i'll try to write it out and then put my code in for you to look at.<br>
the list is a list of ipaddresses and both files are text.</p>

<p>def grab info from a file1<br>
def build my list1 (first code block)<br>
def take list1[0] apply it to file1 and build file2 from it (second code block)<br>
def get email address from list1[0]<br>
def send email with file2<br>
(i can do all of this, it's just getting back to list1[1] that i can't do)<br>
go to list1[1] apply to file1 build file2 send email, etc... until end of list</p>

<pre><code>  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()
</code></pre>

<p>here's code that returns what i want (without ipAddr being an iter) and not looping)</p>

<pre><code>  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()
</code></pre>

<p>hopefully with the line numbers this will help some.  </p>

<p>i made the ipAddr a global so that i can call it from the email function to know that file2 is going to the proper people.<br>
i don't know if this matters or not.  </p>

<p>if i make the ipAddr into an iter (as line 17 and 18) i get -> </p>

<pre><code>TypeError: 'in &lt;string&gt;' requires string as left operand, not list_iterator
</code></pre>

<p>i enjoy learning while i read, yet i'm stuck.  point me in the proper direction and i will read and come back to answer the question.<br>
yet with what i have read people want to build filters, def more functions.</p>

<p>i would think that it should be pretty easy i just can't grasp it.<br>
(post is kind of long, yet wanted to be thourough)</p>

<pre><code>  0 def isp_email_names():
  1     with open('Invalid_names_file') as Invalid_names_file:
  2         with open('ISP_names_file', 'w') as ISP_names_file:
  3             for line in Invalid_names_file:
  4                 if one_ip_each.ipAddr in line:
</code></pre>

<p>Line 4ï¼ one_ip_each.ipAddr is a list_iter, line is a str.
String never contains list_iter.</p>

<p>You could try this:</p>

<pre><code>if line in one_ip_each.ipAddr
</code></pre>

python python-3.x