Skip to content

Instantly share code, notes, and snippets.

@ayushgp
Created February 13, 2018 18:21
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 ayushgp/e46408afd03fdccee0d506f45b83c5a6 to your computer and use it in GitHub Desktop.
Save ayushgp/e46408afd03fdccee0d506f45b83c5a6 to your computer and use it in GitHub Desktop.
"""
Reads a filegiven as CLI arg, puts a number as prefix on each line
and adds the seperator between the lines.
"""
import sys
file_name = sys.argv[1]
f = open(file_name, 'r', encoding="utf8")
contents = f.readlines()
f.close()
sep = "\n\n===================================================================================\n"
for i in range(len(contents)):
contents[i] = str(i + 1) + ". " + contents[i] + sep
file_contents = "\n".join(contents)
f = open(file_name, 'w')
f.write(file_contents)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment