0

That's basically it.

I have a function that is called to process text and translate it into something else. The GUI doesn't allow me to copy paste inside the virtual environment, so I added some dev options on the backend to print what is input through the console so I can copy it and paste it into another document on the side.

Anyways, I basically just want to bus multiple print statements so that ....

OK I'm dumb I solved this and just rephrased everything as a single print statement with commas, but can anyone humor me and nonetheless tell me how to group multiple lines of code and be able to essentially turn them off with a switch on the backend?

I fixed it by changing

print(thing_1)
print("\n")
print(thing_2)
print("\n")

to:

print(thing_1, "\n", thing_2, "\n")
Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
  • Write a function which has the print statements in it and call the function from where you have the print statements now. When you want to comment them out, instead just comment out the call to the new function. – quamrana Jul 24 '23 at 11:27
  • The two pieces of code are not equivalent. – 9769953 Jul 24 '23 at 11:34
  • Quamrana, That was what I was going to do, but it's not quite as elegant (at least overtly to me) for the architecture of what I am working on, although I do employ many summing functions like this. Just in case I'm wrong though, I want to follow up, is there a way to seamlessly turn off a function without a clumsy select > delete > clean up surrounding syntax that calls it so there isn't a blank call that throws and error sort of deal? – Eponymous Sparrow Jul 25 '23 at 07:01

1 Answers1

1
if True:
    print(thing_1)
    print("\n")
    print(thing_2)
    print("\n")

Change True to False and they're "commented out".

Use a boolean variable if you want "a switch on the backend".


If this is purely about printing information, then use logging. Change the logging level between debug, info or warning to have less and less output. There's quite a bit of information about logging in Python; you could start with the logging cookbook.

9769953
  • 10,344
  • 3
  • 26
  • 37
  • Thank you very much. That works perfectly and accomplishes what I wanted exactly. You are very helpful. – Eponymous Sparrow Jul 24 '23 at 14:44
  • There we are, found how to mark it as solved. Thanks for answering what I'm sure is an outwardly absurd looking question. It is simple, but there are so many variations of this idea that I gave up phrasing it to a computer and tried to ask humans. Your idea worked great and generally this approach cleaned up my code and formats into easily seen and understood comments. Thanks for being helpful for my first question on Stack Overflow. I will remember the spirit of generosity when answering silly new questions myself in the future. :) – Eponymous Sparrow Jul 25 '23 at 06:58