var colors python 1

var colors python

#!/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')

Here is what the above code is Doing:
1. The first line imports the init function from the colorama module.
2. The second line calls the init function, passing in the autoreset argument.
3. The third line imports the red and green functions from the fabric.colors module.
4. The fourth line prints the string ‘I know I can be green’ in green.
5. The fifth line prints the string ‘I want the whole line to be green or red’ in green, followed by the latitude and longitude variables, followed by the string ‘at’ in green, followed by the current date and time in green.
6. The sixth line prints the string ‘I know I can be red’ in red.
7. The seventh line prints the string ‘automatically back to default color again’ in the default color.

Similar Posts