If I have the following Python code:
keyphrase = sys.stdin.read()
print(keyphrase)
domain = input()
print(domain)
I run it as follows:
/Users/me/bin/python /Users/me/PycharmProjects/pem_formatter/test_code.py
Please enter a key:
Key line 1
Key line 2
Key line 3
^D
Key line 1
Key line 2
Key line 3
Please enter a domain:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/pem_formatter/test_code.py", line 8, in <module>
domain = input()
EOFError: EOF when reading a line
I tried using a try/except as follows:
try:
print('Please enter a key:')
keyphrase = sys.stdin.read()
print(keyphrase)
except EOFError as error:
print('EOF Error')
but it made little difference:
/Users/me/bin/python /Users/me/PycharmProjects/pem_formatter/test_code.py
Please enter a key:
Key line 1
Key line 2
Key line 3
^D
Traceback (most recent call last):
File "/Users/me/PycharmProjects/pem_formatter/test_code.py", line 12, in <module>
domain = input()
EOFError: EOF when reading a line
Key line 1
Key line 2
Key line 3
Please enter a domain:
Process finished with exit code 1
What do I do in scenarios where I may want to take a multi line input for one variable and a single line for another?