I want to execute the following program called APlusB.py in my OSX terminal, enter two numbers for the inputs and have it compute the values and exit. In my terminal I type:
$ python3 APlusB.py
then I get a little cursor on a blank line, I type
3 4
what do I do after that? If I hit Ctl + d then the program terminates, which is what I want, but it prints 7D and I would prefer if it would just compute my value, and print out 7
# Uses python3
import sys
input = sys.stdin.read()
tokens = input.split()
a = int(tokens[0])
b = int(tokens[1])
print(a + b)
Thank you for your help.
returnkey?7D(or, more likely,7^D) because the program outputs7and you typed Ctrl+D. Terminals handle codes of the form Ctrl+Keyby signaling the reader program, usually a shell or a program invoked directly or indirectly be the shell, about that. Libraries such ascursescan handle stuff so that nothing gets printed and the program can handle the key combo in some way. However, a simple program wont do that, and the terminal will thus echo^Keyby default. For example, most shells, when detecting^C(a.k.a Ctrl+C), will sendSIGINTto the foreground task.D. That's just your terminal mixing up the program's output and other things. If you take your program's output and use it as input for another program, the "D" won't be there.