How to mimic the print function?

Question:

Context

I am making a command-line command line (ironic, I know) and I need to mimic the print() function.

Why?

I want to be able to change the print color (using colorama) without having to place Fore.COLOR everywhere.

What I have right now

def pprint(*prompt):
  for strr in prompt:
    print(console_color+str(strr))
  return

Obviously, this wouldn’t work with other arguments like sep or end which is why I need to mimic print().

Asked By: Vlone

||

Answers:

Use **kwarg to take keyword arguments and pass them along to print(). Use a generator to concatenate with all the values.

def pprint(*strings, **kwarg):
    print(*(console_color+s for s in strings), **kwarg)
Answered By: Barmar
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.