Run 'main' and Run selection yields different results.

I am trying to run a simple python program in PyCharm,

import sys

# for i in open("test"):
for i in sys.stdin or []:
data = i.split()
a = int(data[0])
b = int(data[1])

When I press shift+F10 the code runs and prompts me for input. All is good.

But when I select the code and press Alt + Shit + E (Run selection) I get the following error in Python Console,

Traceback (most recent call last):
File "<input>", line 4, in <module>
TypeError: 'StdIn' object is not iterable

Why the discrepancy?


Thank you!

1 comment


Got to say, I can't reproduce your error. When I run your code as a selection, the same happens as a normal run, with the exception that I can't type anything to standard input in this case, so the thread just sitting in memory waiting for the input. But I don't see any errors.

Can you share your PyCharm and Python versions?


Please sign in to leave a comment.