0

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
6
  • 2
    Why do you need to paste this into the interactive window in the first place? Why not just write it into a .py file and execute the file? Commented Aug 3, 2022 at 20:07
  • I just want to select the lines I want to test and run those instead of executing the whole file. Commented Aug 3, 2022 at 20:14
  • 1
    Well, in that case as a hacky workaround you can wrap them in an if True: block - the REPL won't evaluate an indented block until it's over (plus one newline). Commented Aug 3, 2022 at 20:15
  • Ah interesting! Thank you! Commented Aug 3, 2022 at 20:18
  • 1
    right that is one solution, though that's a bit inconvenient to do it with multiple inputs in your code. Commented Aug 3, 2022 at 20:50

1 Answer 1

1

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

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

1 Comment

Tested on IPython and it works! I added "python.terminal.launchArgs": ["-m", "IPython", "--no-autoindent"] to my VSCode setting.

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.