I am trying to run a program on a jupyter notebook that accepts user input, and I cannot figure out how to get it to read standard input. For example, if I run the code with shift-enter:
a = input() print(a)
the cell indicates it is running, but does not accept input from me. How do I get it to accept input?
By using Jupyter Notebook in this example, it makes it really easy to see what the prompt looks like when calling that input() function. We can type some characters into the prompt for our name. Then, we can add the code to print() that variable. We might want to make that output just a little more interesting.
Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable.
Use the raw_input()
(for Python 2) or input()
(for Python 3) methods.
Example code:
a = raw_input() print(a)
Example notebook:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With