On a close read, I think you do indeed have a single, clear, appropriately scoped question underlying all of this. I don't think it should be deleted (unless you're giving up on asking it). After writing most of this post, I also don't think it's a duplicate. (I don't think you're really asking about logging, although that's a reasonable guess reflected by the initial attempt someone else made to answer.)
But it needs to be fixed. It's buried under so much irrelevant discussion that the question creates the impression of asking multiple unrelated additional things.
A well-asked question should almost always fit on your screen without scrolling, unless asking it really does require too much code for that to work. In order to get there:
Get rid of the code
In your case, I don't think any code is necessary, because:
You are asking a "how-to" question, not asking us to explain the behaviour of existing code—therefore, any code that you do show us should be part of what's needed to specify the problem. In other words, a minimal reproducible example is not necessary or appropriate, because there isn't anything to "reproduce".
But describing your problem doesn't require code either, and the code structure that you do show doesn't help with describing the problem. The problem is that you have some main loop for your program that will call into more complex functionality, and you want to make some global change (disabling print
s in bulk) in that functionality. The only interesting feature of the omitted code is that there's presumably a lot of it (and, in particular, a lot of places where print
is called). It doesn't matter what the main loop looks like, because by your own description, the problem isn't there.
It's not about you
We ruthlessly eliminate "noise" from questions here. That is, we don't want social pleasantries, comments about yourself or your mindset approaching the problem, or anything that isn't necessary to understanding the question. It's all well and good, for example, that you want to avoid running into an XY problem; but it isn't really actually our responsibility here to steer you away from one. This is not a discussion forum, and the purpose of the question is not to make your code the best it can be, or even to solve the apparent problem. The purpose isn't even to help you (which is part of why we expect more than a request for help in questions). The purpose is to help everyone, by creating a question that could meaningfully be asked by others, found by said others by using a search engine, and be answered in a way that is useful to everyone who would ask it.
What's actually relevant?
It should be obvious that using PyCharm doesn't matter. Why? Because you aren't asking about the process of using an editor to write the code; you're asking about what the code should contain. You can make the code contain anything you want, with any editor you want. Programs like PyCharm don't control how the code works. Python is Python.
Furthermore, it doesn't matter that you want to add machine learning to the project. (Also, please stop worrying about this now! Make the existing code work to your satisfaction first. It's vital to have a solid understanding of the fundamentals of programming, before you try to use anything more sophisticated.) Why? Because you would have the same problem regardless: the print
s are already in your code. Yes, putting two machine learning bots against each other would allow for the games to be much faster (the program would never be waiting for an input
). But that's just forcing you to realize a problem that's already there. Further, you already apparently have "AI" in the program, since there's a decide_computers_move
function. You could equally well make that algorithm compete against itself.
Finally, it doesn't matter how long print
takes, and that will also depend a lot on the environment (but if it concerns you, then you could look up how to time things—see: How do I get time of a Python program's execution? ; How do I measure elapsed time in Python? ; How can I time a code segment for testing performance with Pythons timeit? —and find out by trying it). "I want to control how much text appears in the terminal, and which text" is already sufficient justification.
Is there actually a question?
In the existing code, when you call decide_computers_move
, does it still print
detailed information about the gamestate
? Or does that function simply use the gamestate
that was passed to it to do some calculations?
If it already works without print
ing, then why should there be any problem with using the same approach to get an answer from the ML bot?
Conclusion
Here's an example what a question of this sort should typically look like:
I'm making a game that includes some complex logic and which supports both human and computer (AI) players. There are a lot of print
statements scattered throughout the code, intended to describe the game state to human players. I want to have two computer players play against each other, and not see all those messages.
Suppose I have separate functions that determine a player's next move, for human and AI players, and a main loop that chooses and calls these functions. How can I structure the rest of the code, such that the program only displays messages to human players?
Yes, good how-to questions really are normally that short. The best ones are often even shorter.
Notice that the "I" statements here aren't actually about you—they're about the code and about the desired result. That's important.
What will happen at this point, most likely, is that people will ask for a bit more detail, to make sure they understand the question—maybe because they think you do have an XY problem and want to get that out of the way in the comments. (They're trying to be helpful, but again it's not relevant to the purpose of the site.) Or maybe they think the question is trivial ("... just don't write print
inside the function that gets moves for the computer players? What's the problem?") and you can re-think whether there actually is a question, and if so, how to make that fact clear.