Home > front end >  What is the reason that PyCharm is not executing code correctly while everything is fine in the Pyth
What is the reason that PyCharm is not executing code correctly while everything is fine in the Pyth

Time:05-22

Code running in PyCharm does not run as it should. Here it is:

crd = [input().split() for _i in range(int(input()))]

print(crd)

The input:

4
1 2
1 2
1 2
1 2

Take a look at the screenshot of the code running in the console:

enter image description here

The output:

[['1', '2'], ['1', '2'], ['1', '2'], ['1', '2']]

And take a look at what happens with this code in PyCharm:

enter image description here

The output (I can't even complete the input):

[[], ['1', '2'], [], ['1', '2']]

I have no idea what is going on here.

P.S. I have already done the following:

  1. Uninstalled PyCharm and Python.
  2. Removed all folders related to them (in AppData and so on).
  3. Downloaded and installed the latest versions of PyCharm and Python.
  4. Rebooted my laptop.
  5. Created a completely new project.

But it didn't help.

P.P.S. The option "Emulate terminal in output console" is not enabled:

enter image description here

CodePudding user response:

This is a bug. I just tried it and it does the same thing on my machine, however when I run it through the pycharm debugger it allowed me to enter all 4 inputs and output the correct result.

A temporary workaround is to enable the "Emulate terminal in output console" for a given in Modify Run Configurations which is available in the context menu if you left click on main.py enter image description here

here is a link to the issue tracker on the bug https://youtrack.jetbrains.com/issue/PY-54238/STDIN-is-lost-for-a-second-input-call

  • Related