I'm trying to print Python output on the Terminal.
Everything works fine if I have to print a phrase, problem starts when the phrase contains variables.
This is the code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
from colorama import init
init(autoreset=True)
from fabric.colors import red, green
latitude = 36.02866
longitude = 70.77258
print ("\033[92m" + 'I know I can be green' + "\033[0m")
print ("\033[92m" +'I want the whole line to be green or red',latitude,',',longitude, 'at', datetime.datetime.now(), "\033[0m")
print ("\033[91m" + 'I know I can be red' + "\033[0m")
print ('automatically back to default color again')
As you can see just the first part of the second phrase is colored.
But I need the whole phrase to be colored!
This should work by formating the string, instead of giving new parameters to the function print()
:
print ("\033[92m" +'I want the whole line to be green or red {0}, {1} at {2}'.format(
latitude, longitude, datetime.datetime.now())+ "\033[0m")
print ("\033[91m" + 'I know I can be red' + "\033[0m")
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments