Home > OS >  How to mimic the print function?
How to mimic the print function?

Time:10-15

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().

CodePudding user response:

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)
  • Related