tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.56k stars 252 forks source link

Setting cprint to a variable, then printing it produces word "none" in Windows using Geany #254

Closed StewAlexander-com closed 4 years ago

StewAlexander-com commented 4 years ago

Hi,

I created a prompt (was using termcolor "colored" function, but didn't work with Windows)

# Magenta prompt
prmpt_magenta = cprint("> ", 'magenta')

Then I tried calling it in a function: StartNum = float(input(prmpt_magenta))

The script compiles in Geany, but when execute the program I get the word "none"

Ideas?

StewAlexander-com commented 4 years ago

Yeah, I get the same thing here...

It prints "hello" (in red), then "none"

#!/usr/bin/env python3

# Import colors from termcolor
from termcolor import *

#import colorama to print colors to Windows systems
import colorama
colorama.init()

hello = cprint("hello", 'red')
print(hello)
wiggin15 commented 4 years ago

Hi there! This doesn't seem to be related to colorama. The issue exists even without importing and initializing colorama. Apparently, "cprint" is a function that already prints, so the call to cprint("hello", 'red') prints the red "hello", and the print of the variable, hello, which is assigned the return value of the function cprint (None) will print "None". Just skip the second "print" and you'll be good.