Skip to content

Instantly share code, notes, and snippets.

Created March 14, 2016 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/06299d9943cc9cc8262d to your computer and use it in GitHub Desktop.
Save anonymous/06299d9943cc9cc8262d to your computer and use it in GitHub Desktop.
# Only need to compile the regex once, outside the loops
orderItem = re.compile("[][A-Z]{2}[0-9]{3,7}[.]")
for file in os.listdir('.'):
detailsList = []
if file.endswith(".log"):
logfile = open(file) # File opens as read only by default
for line in logfile:
orderItemMatches = orderItem.findall(line)
if orderItemMatches:
# orderItemMatch = orderItemMatch.translate(None, ".") # Not sure what the translate method does
detailsList.append(orderItemMatches[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment