I've created a python method to print data to screen and in a file:
def printf(handler, string): print(string) sys.stdout.flush() if handler is not None: handler.write(str(string)) handler.write("\n")
The code works just fine when I'm running it in the virtual env. However, when I use the exe created using pyinstaller, I run into the error :
AttributeError: 'NoneType' object has no attribute 'flush'
The call to the flush method seems to cause the crash but I don't know how to solve this.I did not find a solution after looking on the net.
How can the builtin sys.stdout
be None
?