Skip to content

Instantly share code, notes, and snippets.

@willwangcc
Created June 2, 2019 17:30
Show Gist options
  • Save willwangcc/84adb332a8acd898439ba4a20ee33d40 to your computer and use it in GitHub Desktop.
Save willwangcc/84adb332a8acd898439ba4a20ee33d40 to your computer and use it in GitHub Desktop.
files (.txt) to formatted string for latex
import os
path = "/Users/wangzhixiang/Developer/github/all-about-will-wang/days"
files = []
for filename in os.listdir(path):
files.append(filename)
files.sort()
def format(input):
if len(input) != 6:
print(input)
raise KeyError
a, b, c, d, e, f = input
output = ""
space = "\n\n\\bigskip\n"
output += a + space
output += b + space
output += c + space
output += "——" + " " + e + space
output += f + "\n\n\\newpage\n"
return output
for file in files:
with open(path+"/"+file, 'r', encoding = "utf-8") as reader:
temp = reader.read().split()
output = format(temp)
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment