Python Forum
problem using coloeama module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem using coloeama module
#1
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?
Reply
#2
(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()
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
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.
Reply
#4
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with memory_graph module akbarza 3 375 Mar-04-2024, 10:15 AM
Last Post: snippsat
  problem in using subprocess module akbarza 5 1,042 Sep-24-2023, 02:02 PM
Last Post: snippsat
  problem in import module from other folder akbarza 5 1,440 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  problem in using pyqrcode module to create QRcode akbarza 9 2,002 Aug-23-2023, 04:17 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,019 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  Problem with module time and leap seconds Pedroski55 3 1,257 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  keyboard module; must be root problem philipbergwerf 2 19,127 Apr-04-2021, 11:40 AM
Last Post: philipbergwerf
  Problem with Flask Bcrypt import module marcello86 2 5,746 Aug-31-2020, 08:10 PM
Last Post: marcello86
  Js2Py module not found problem Charliedactyl1 5 7,946 Jun-14-2020, 07:39 PM
Last Post: buran
  Python 36-32 problem encoding module not found mkgrtn 0 2,446 Apr-14-2020, 09:57 PM
Last Post: mkgrtn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020