I usually write python in emacs.
I often want to re-evaluate my file, which I can do with Ctrl-C Ctrl-C, which causes the interpreter to reload the whole file, and then I can continue to play.
therefore, if I write a program that accepts input, I usually find myself with two lines:
lines = open("/home/jla/inputfile").readlines()
the first line is "what to do during development" (read from the input file with a well-known example) the second is "what to do if you run from the command line" (read from stdin or the file name provided)
Obviously this is bad, so I think:
if in_emacs(): lines = open("/home/jla/inputfile").readlines() if run_from_shell(): lines = fileinput.input() else: oops()
And I know how to write oops() , but I'm a little stuck with in_emacs() and run_from_shell() , and I wonder if you can help.
source share