pythoncoloramatermcolor

Colorama Formatting Strings


I am back with another problem with my program but this time its with Colorama, and Termcolor(Both of which are being used together)

The format I am looking for: Colors Module [LOADED] Please not the word "Loaded" and ONLY that word should be green

The script:

print 'Colors module',"[", cprint("LOADED","green"),"]"

I want to know how I could get it to format the way I am hoping for

Currently the word loaded is green like it should however its the ending ] thats the problem, it is on the next line

Colors module [LOADED
 None ]

Does anyone know how to fix this? (PS if you recommend another module instead of those to, I am using python version 2.7)


Solution

  • The reason you're getting a line break is because the cprint call gives you one. I'm not sure what you need colorama for, the following works for me, albeit in python 3 (which you should be using):

    from termcolor import colored
    print("Colors module [" + colored("LOADED", "green") + "]")
    

    enter image description here