I use the following color class found in this question "Print in terminal with colors?"
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
print(bcolors.FAIL + "some error" + bcolors.ENDC)
When I run this in my python script editor I get the output in the correct red error color:
some error
[Finished in 18.782s]
However when I run from command prompt, or using powershell (my intended console output) I get the this output:
[91msome error[0m
(there are arrows before each "[" but would not show every time I press save)
update:
Here is a capture of the output:
This seems a very attractive approach because I do not have to download or import any new modules and could just include it in a few lines in my script. This was voted to be the best answer but I could not get it working because it seems to interpret \033
as some ASCII for the arrow sign.
In the linked answer you can also find the following statement:
This will work on unixes including OS X, linux and windows (provided you use ANSICON, or in Windows 10 provided you enable VT100 emulation).
Since you are asking about powershell which of the two have you tried?
.
Perhaps you might rather want to look into Colorama
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With