Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm output error messages interspersed with console output. How to fix this?

Tags:

I'm running PyCharm Community Edition 4.0.4

Does anyone know why the error messages don't display after the console output?

Thanks

C:\Python27\python.exe "F:/Google Drive/code/python_scripts/leetcode/lc_127_word_ladder.py" Traceback (most recent call last): START   File "F:/Google Drive/code/python_scripts/leetcode/lc_127_word_ladder.py", line 68, in <module>      print sol.ladderLength('talk', 'tail', set) Graph:   File "F:/Google Drive/code/python_scripts/leetcode/lc_127_word_ladder.py", line 54, in ladderLength hall ['fall']     for item in graph[node[0]]: fall ['hall'] KeyError: 'talk' End Graph:  Visited =  {'talk': 0}   Node =  ['talk', 0] Queue Before =  deque([])  Process finished with exit code 1 

If you'll notice, print statements such as START, Graph:, hall ['fall'], up to Queue Before = deque([]) all happen within the functioning part of my code. The Error messages should appear after all this.

like image 497
newbie Avatar asked Jan 18 '15 20:01

newbie


People also ask

How do I enable console in PyCharm?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Build, Execution, Deployment | Console | Python Console. Select any available interpreter from the Python interpreter list.

Why does PyCharm run on console?

The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes. and check the Special Variables list. The console is available for all types of Python interpreters and virtual environments, both local and remote.

How do I get output in PyCharm?

To set window mode for the tool window, right-click the tool window tab and select View Mode | Window. Create a new tab for a data source sessions and output results. Stay on the output pane of the selected query console in the Services tool window.


2 Answers

This is caused by PyCharm mixing print statements from stdout and stderr. There's a fix if you add the following line to your idea.properties file:

output.reader.blocking.mode=true 

Get to idea.properties via Help | Edit Custom Properties.

like image 145
Saul Avatar answered Oct 07 '22 00:10

Saul


might just be an issue with the stdout.

a workaround would be to use sys.flush.stdout() after your print statements.

import sys  do_something() print("Your print statement") sys.stdout.flush() 
like image 33
mirmo Avatar answered Oct 07 '22 01:10

mirmo