I'm using Pygame/SDL's joystick module to get input from a gamepad. Every time I call its get_hat()
method it prints to the console. This is problematic since I use the console to help me debug and now it gets flooded with SDL_JoystickGetHat value:0:
60 times every second. Is there a way I can disable this? Either through an option in Pygame/SDL or suppress console output while the function calls? I saw no mention of this in the Pygame documentation.
edit: This turns out to be due to debugging being turned on when the SDL library was compiled.
If you don't want that one function to print, call blockPrint() before it, and enablePrint() when you want it to continue. If you want to disable all printing, start blocking at the top of the file.
system('cls') to clear the screen. The output window will print the given text first, then the program will sleep for 4 seconds and then screen will be cleared and program execution will be stopped.
The visual display provides console output and the keyboard provides "console input." The simplest way to write to the console or visual display is python's print function.
Just for completeness, here's a nice solution from Dave Smith's blog:
from contextlib import contextmanager import sys, os @contextmanager def suppress_stdout(): with open(os.devnull, "w") as devnull: old_stdout = sys.stdout sys.stdout = devnull try: yield finally: sys.stdout = old_stdout
With this, you can use context management wherever you want to suppress output:
print("Now you see it") with suppress_stdout(): print("Now you don't")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With