Skip to content Skip to sidebar Skip to footer

Python Not Printing Output

I am learning to use electron js with python and I am using python-shell so I have the following simple python script: import sys, json # simple JSON echo script for line in sys.s

Solution 1:

Output is often buffered in order to preserve system resources. This means that in this case, the system holds back the Python output until there's enough to release together.

To overcome this, you can explicitly "flush" the output:

import sys, json

# simple JSON echo script
for line in sys.stdin:
    print(json.dumps(json.loads(line)))
    sys.stdout.flush()                      # <--- added line to flush output

If you're using Python 3.3 or higher, you may alternatively use:

import sys, json

# simple JSON echo scriptfor line in sys.stdin:
    print(json.dumps(json.loads(line)), flush=True)   # <--- added keyword

Post a Comment for "Python Not Printing Output"