I have a python program where I pass in a file, I read this file and then split the line at a colon. I then print both these parts, do some checking on it and pass it into a function where if its a match it prints out the match then returns. However I cannot figure out how to then get the next line in my file, the program currently just keeps going over and over on that one line
with open(myfile,'r') as hf:
for l in hf:
part1 = l.split(":")[0].strip()
part2 = l.split(":")[1].strip()
print part1
print part2
print "**************"
for file in filenames:
print "Starting " + file
if ".txt" in file or ".lst" in file:
file = os.path.join(mypath, file)
with open(file,'r') as f:
for line in f:
for word in line.split():
ThenWord(part2,word)
I have tried break, continue and else, along with next() but I can't seem to get it working, or it's in the wrong place. How would I get the next line from the open file and then start the for loop again to split at the colon, line 3 and 4.
EDIT: I have added in 2 breaks, but the files I try and match the word to (for file in filenames) only reads the first file then moves onto the next line from myfile.
with open(myfile,'r') as hf:
for l in hf:
part1 = l.split(":")[0].strip()
part2 = l.split(":")[1].strip()
print part1
print part2
print "**************"
for file in filenames:
print "Starting " + file
if ".txt" in file or ".lst" in file:
file = os.path.join(mypath, file)
with open(file,'r') as f:
for line in f:
for word in line.split():
ThenWord(part2,word)
break
break
def ThenWord(salt,word):
salted = salt + word
m = hashlib.md5()
m.update(salted)
if m.hexdigest() == hash:
print "************ " + hash + " ************"
print "******* Enough said - " + word + " ******* "
return
I want it so that once it has found a match, it moves on to the next hash in the file (myfile) without scanning through every other file in filenames.
for line in f.readlines().with open(myfile,'r') as hf: for l in hf:for file in filenames. Blocs starting withiforwithare not loops.