Yar
Yar

Reputation: 7476

Get Input in Python Interactive Mode

Say I have a simple script that depends on my input:

w = input()
print(f'Input is {w}')

If I copy and paste this script (both lines at the same time) into the interactive window, it won't pause on input line to receive an input.

>>> w = input()
print(f'Input is {w}')
>>>

Is there any way to change this behavior?

Update: This seems to work just fine on Pycharm:

In: w = input()
print(f'Input is {w}')
>? test
Input is test

Upvotes: 0

Views: 941

Answers (1)

wjandrea
wjandrea

Reputation: 33145

You could use IPython, which supports pasting blocks:

In [1]: w = input()
   ...: print(f'Input is {w}')
a
Input is a

Just in case that doesn't work, you could use the command %paste to load and execute the clipboard contents, or %cpaste so that you can paste manually:

In [2]: %paste
w = input()
print(f'Input is {w}')

## -- End pasted text --
b
Input is b

In [4]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:w = input()
:print(f'Input is {w}')
:--
ERROR! Session/line number was not unique in database. History logging moved to new session 1903
c
Input is c

(I'm not sure what this error means BTW, though I notice the "In" number ticked up once more than it should have.)

See also: Paste Multi-line Snippets into IPython

Upvotes: 1

Related Questions