5

I'm using Git Bash to run my Python scripts on Windows. I noticed that the console doesn't print while my scripts are running. All the strings are printed just when the scripts finish. I read that is a buffer and line break issue. How can I fix it?

Community
  • 1
  • 1
bodruk
  • 3,242
  • 8
  • 34
  • 52

2 Answers2

6

I am using MINGW64 on Windows10, and python -u works for me. For example,

   python -u foo.py

From python --help:

-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'
PeterS
  • 139
  • 8
Ted
  • 83
  • 1
  • 5
3

I solve this including sys.stdout.flush() after each print().

bodruk
  • 3,242
  • 8
  • 34
  • 52
  • I'm using freshly installed Windows 10, git bash and `Python 3.5.1 :: Anaconda 2.4.1 (64-bit)` and I don't see anything printed even after flushing or causing an error. Works fine at `cmd`, any suggestions on how to get it to work in Mingw64? `python -u` doesn't help either, I'm not seeing even `>>>` at line beginning. – NikoNyrh Jan 14 '16 at 12:50