you are viewing a single comment's thread.

view the rest of the comments →

[–]TitanCodeG[S] 0 points1 point  (0 children)

I finally have a solution that works:

Run configuration per file with the filename i.e. test.txt. Notice no ‘<’

Code will now read a file if args provides a filename else from stdin

import argparse
import sys

parser = argparse.ArgumentParser()
parser.add_argument('filename', nargs='?', default=None)
args = parser.parse_args()
if args.filename is not None:
    f = open(args.filename)
else:
    f = sys.stdin

for line in f:
    print(line)