I'm trying to write a small graph parser that reads from stdin
and writes the processed output to stdout
along the lines of:
# parser.py
G = defaultdict(list)
for line in sys.stdin:
node, neighbor = line.split()
G[node].append(neighbor)
print(G)
I would like to invoke the script with python -i parser.py < data.txt
and interact with the objects I've created, but the interpreter always exits after the code runs even when I invoke Python with the -i
option. N.B. The same thing occurs with ipython
; it even confirms for me that I "really want to exit."
A workaround is to write the code to use a specific file passed in as an argument, but I was wondering if there is a way to make Python not exit the interpreter in the example above.