Last active
August 27, 2021 14:31
-
-
Save interstar/715c75996c444666c9c5bf2a1ca6d2b8 to your computer and use it in GitHub Desktop.
recursively include text files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, re | |
# Run like this : | |
# python3 rectext.py toplevel.txt | |
# | |
# include statement looks like this | |
# @include fname.txt | |
def slurp(fName) : | |
with open(fName) as f : | |
return (l.strip() for l in f.readlines()) | |
def xclude(fName) : | |
for l in slurp(fName) : | |
if re.match("@include",l) : | |
for l2 in xclude(l.split(" ")[1]) : yield l2 | |
else : | |
yield l | |
for l in xclude(sys.argv[1]) : print(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment