Skip to content

Instantly share code, notes, and snippets.

@z-------------
Last active August 29, 2015 14:22
Show Gist options
  • Save z-------------/e5513c539148009ebcb5 to your computer and use it in GitHub Desktop.
Save z-------------/e5513c539148009ebcb5 to your computer and use it in GitHub Desktop.
Python script for making files with content from a template
#!/usr/bin/env python3
import sys
import getpass
templates_dir = "/home/{user}/Templates/".format( user=getpass.getuser() )
arg = sys.argv[1]
output_filename = sys.argv[1]
input_fileext = arg[arg.rfind(".")+1:]
input_filename = input_fileext + "." + input_fileext
if input_filename:
input_content = open(templates_dir + input_filename).read()
output_file = open(output_filename, "w")
output_file.write(input_content)
output_file.close()
else:
print("i confuse ;_;")

template.py

???

Makes files with content from your Templates directory.

Usage

template index.html
# makes a file called "index.html" based on the template file "html.html"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment