Quote (carteblanche @ Apr 26 2015 02:17pm)
is it still running forever? does that mean it's printing out thousands of "match found" and "error no match"?
if so, add a print / debug statement so you see what "eachLine" holds.
Negative. I changed the program a bit:
Code
import re
fileName = input('Please enter the name of the file containing the input zicpcodes: ')
fileObject = open(fileName, 'r')
string = fileObject
for eachLine in fileObject:
string = string
pattern = '^([0-9]{5}|[0-9]{9})$'
m = re.match(pattern, string)
with open(fileName) as input_file:
for i, line in enumerate(input_file):
if m is not None:
print("Match found with: ", string, "\n")
else:
print("Error - no match with: ", string, "\n")
fileObject.close()
Basically, I think the logic is right as it will iterate through each line and check the pattern against each string, but I'm just not sure what to set "string" equal to, hence it's just string = string.
"re" requires the pattern and string buffer, but I don't know what to use as the string. I want to use the strings/lines in the file, but setting it equal to fileObject also doesn't work.