Skip to content

Instantly share code, notes, and snippets.

@Ja1meMartin
Last active January 19, 2016 02:07
Show Gist options
  • Save Ja1meMartin/db1b71ed90921aff24fa to your computer and use it in GitHub Desktop.
Save Ja1meMartin/db1b71ed90921aff24fa to your computer and use it in GitHub Desktop.
#Context Managers autoclose file
with open(sourcefile,'r') as infile, open(targetfile,'w') as outfile:
# split on your search string
# if not found list of length 1
# if found list with two strings either size
line_iterator = (str(line).split("recap?id=") for line in infile) # generator lazy evaluation
# take the second item in the list
# ignore the first len(search_str) characters
ids = len ( line[1][searchlen:] for line in line_iterator if len(line) > 1)
for id in ids:
outfile.write(game_id)
outfile.write("\n")
print ( str( len( ids ) + " : records written")
print ("Parse end")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment