def replace_with_file_contents(fname):
"""Action to perform when successfully matching parse element definition for inputFrom parser.
:param fname: str - filename
:return: str - contents of file "fname"
"""
try:
with open(os.path.expanduser(fname[0])) as source_file:
result = source_file.read()
except IOError:
result = '< %s' % fname[0] # wasn't a file after all
# TODO: IF pyparsing input parser logic gets fixed to support empty file, add support to get from paste buffer
return result
评论列表
文章目录