No, you only implement this one:
def parseLog(file):
list = []
for line in file:
list.append(parseEntry(line))
return list
Or better (more pythonic imho):
def parseLog(file):
for line in file:
yield parseEntry(line)
The second version is lazy (if file reading is lazy), so you can even abort parsing or fix the state on an error. Here are your different versions all reusing parseLog from above and equivalent line count to condition handling:
def parseLogLoudly(file):
for entry in parseLog(file):
if entry.failed:
print "Warning:", entry.message
else
yield entry
def parseLogSilently(file):
for entry in parseLog(file):
if not entry.failed:
yield entry
def parseLogInteractively(file):
for entry in parseLog(file):
if entry.failed:
yield askToFixEntry(entry)
else
yield entry
(Haskell's Either has "Left a" or "Right b". I want something like "Just value" or "Error msg", but you are right Either is nearer than Maybe)