Python Forum

Full Version: problem using coloeama module
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi
the bellow code:
'''
colorama usage.
from net has been taken.
'''

from colorama import Fore
print(Fore.YELLOW+" hello,world")
print(Fore.RED+" hello,world")
print(Fore.BLUE+" hello,world")
print(Fore.CYAN+" hello,world")
print(Fore.GREEN+" hello,world")

import time
t1=time.monotonic()
x=[i for i in range(10_000_000)]
t2=time.monotonic()
print(f"duration : {t2-t1}")
after runing in idle, output is:
Output:
 hello,world  hello,world  hello,world  hello,world  hello,world duration : 1.0160000000000764
also in cmd, the output is the above except that there is a left arrow replacing square.
The above code aims to write in output with different colors. what is the problem?
(Jan-07-2024, 11:40 AM)akbarza Wrote: [ -> ]The above code aims to write in output with different colors. what is the problem?
Colorama can only work in terminals that interprete ANSI escape sequences. This is not the case of the Idle shell, so I don't think it can work in Idle.

I don't know Windows Cmd, but it seems that it works in the PowerShell. Don't forget to call
colorama.init()
There are no colors when running in IDLE. That is the fault of IDLE. If you continue to use IDLE, run your programs in CMD or powershell to verify there is a problem before spending any time trying to debug.
(Jan-07-2024, 12:00 PM)Gribouillis Wrote: [ -> ]
(Jan-07-2024, 11:40 AM)akbarza Wrote: [ -> ]The above code aims to write in output with different colors. what is the problem?
Colorama can only work in terminals that interprete ANSI escape sequences. This is not the case of the Idle shell, so I don't think it can work in Idle.

I don't know Windows Cmd, but it seems that it works in the PowerShell. Don't forget to call
colorama.init()
hi
as you mentioned in the link in your reply, the init() is required and it must be written as
 init()
. also, it shows in cmd colorfully.
thanks for reply.