Apparently the version of pygame I'm using has an issue where debug statements have been left in - How to suppress console output in Python? while using joystick.get_axis
. That is the issue, but I have been unsuccessful in trying to use the methods presented in those answers. Each of the methods still printed the SDL_JoystickGetAxis value
.
I also tried this blog but I was still outputting to the console. Thinking it may be an issue with stdout
vs stderr
, I tried suppressing stdout
then stderr
then both, to no avail.
Basically my code is constantly printing SDL_JoystickGetAxis value:0
or whatever the axis value is. How do I suppress these debug statements?
import os
import sys
from contextlib import contextmanager
@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
Later on in my code I use that function:
if speedchange == False and headingchange == False:
time.sleep(0.1)
with suppress_stdout():
speed_ax = joys.get_axis(1)
head_ax = joys.get_axis(0)
Which still outputs debug statements