0

I am writing a python code for a class which needs multiple lines of inputs.

For example I need the input to be in the format:

3 14
12 10
12 5
10 5

When entering this manually on the terminal, I do not know how to signal an end of input.

I have been working around it by entering the inputs in txt files and reading these.

1
  • 1
    What code are you using to read this? A standard approach is to use a specific string (that isn't an otherwise valid input) to tell your code to stop reading. (For example, early text editors in insert mode would read lines of input until you entered a single . as a line.) Commented Feb 5, 2023 at 14:54

3 Answers 3

2

On Linux, use Ctrl+D to type "end of file". On Windows, use Ctrl+Z.

Sign up to request clarification or add additional context in comments.

Comments

0

Besides the control-d, in bash, you can also:

pythonscript <<EOF
3 14
12 10
12 5
10 5
EOF

Comments

0

On linux and unix you can find what the EOF char is using

stty -a

it will show something like

...
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <under>;
...

indicating the eof is ^D, which you can also change using stty.

Then, you can type ^D to signal EOF to a process that's reading its input from the terminal.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.