The code is suppose to take a string of multiple arguments and split them with the “Split()”. It does do that, but it only passes the first argument to the “CheckList()”. So if I type ” 1 2 4″ it will only pass “1” to CheckList. Everything else works as it should.
import re
def CheckList(Start):
DoIt = 0
s = int(Start)
End = s + 1
End = str(End)
for PodCheck in F.readlines():
if re.match('Pod' + End, PodCheck.strip()):
DoIt = 0
if re.match('Pod' + Start, PodCheck.strip()):
DoIt = 1
if DoIt == 1:
print PodCheck,
return
def Split(P):
Pods = P.split()
for Pod in Pods:
CheckList(Pod)
return
F = open("C:\Users\User\Desktop\IP_List.txt")
Pod = raw_input('What pod number would you like to check?: ')
Split(Pod.strip())
print 'Done'
Your problem is right here:
The first call to
CheckListuses up all the data inF. Subsequent calls toChecklistskip theforloop because there is nothing left to read.So after opening
Fyour should read all of it’s data. Without changing too much of your code I would add this after you open your file:And change to loop in
CheckListto