Created
February 1, 2017 14:34
-
-
Save Makistos/9b3279317223917dfd3d971fbbef8736 to your computer and use it in GitHub Desktop.
Read files recursively. Useful for e.g. command files. #python #file-handling
This file contains hidden or 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
def parse_test_file(filename): | |
retval = [] | |
with open(filename) as f: | |
lines = f.read().splitlines() | |
path, script = os.path.split(os.path.abspath(filename)) | |
cwd = os.getcwd() | |
if cwd != path: | |
os.chdir(path) | |
for line in lines: | |
if line.startswith('/include'): | |
retval = retval + parse_test_file(line[9:]) | |
else: | |
retval.append(line) | |
if cwd != path: | |
os.chdir(cwd) | |
return retval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment