How to give jupyter cell standard input in python?

Alex picture Alex · Jan 23, 2016 · Viewed 78.6k times · Source

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?

Answer

Rahul Tripathi picture Rahul Tripathi · Jun 3, 2017

Use the raw_input() (for Python 2) or input() (for Python 3) methods.

Example code:

a = raw_input()
print(a)

Example notebook: