Please bear with me, I'm only about a week into Python.
This code is something that I wanted to do once I completed the chapters dealing with opening and reading files, and RegEx. I always feel like I'm over complicating the code. Please take a look and let me know if this is sound and where it can be improved. There are a lot of concepts I haven't learned yet. I'm teaching myself out of a book.
This code is meant to open a log file (will eventually be retrieved real-time), go through it line by line using RegEx to find "Fail", add those lines reporting failures to a list and return the completed list as a string joined with new lines.
#!/usr/bin/python import os import re myFile = '/home/nick/python/chap8ReadingWritingFiles/15Jan2016_000000.txt' def RegEx(file): openFile = open(myFile, 'r') myResList =  myList = openFile.readlines() myReg = re.compile(r'Fail') for i in (myList): #print(i, end='') result = myReg.search(i) if result != None: #print(i, end='') myResList.append(i.rstrip()) final = '\n'.join(myResList[:]) return final print() print('Results:') print(RegEx(myFile)) print()