0

I'm learning python and have written a small script that pulls data from a webpage and displays it on the screen.

It assigns a variable to each item it pulls from the webpage. I have a variable that has two out comes.

ham_lic = Active

or

ham_lice = Expired

It then prints that value to the screen.

print "License: ("+ham_lic+")"+"\n"

I'm trying to figure out how to print the license status red when the value is 'expired' and green when the value is 'active'.

Even just reference material would be greatly appreciated.

Corrosive
  • 86
  • 1
  • 11

1 Answers1

1

It depends on the platform you're on. Try:

if ham_lic == 'Active':
    print "License: (\033[92m"+ham_lic+"\033[0m)"+"\n"
else:
    print "License: (\033[91m"+ham_lic+"\033[0m)"+"\n"
Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
  • I think that's close.. I get this as the output. License: ([92mActive[0m) – Corrosive Nov 24 '13 at 19:39
  • @Corrosive: I took it from http://stackoverflow.com/q/287871/1267329 and it works on my Mac. But it may or may not work for your platform. What terminal/system are you using? – Simeon Visser Nov 24 '13 at 19:40
  • Using idle on windows.... I'll open up an ssh session to one of my linux boxes and give it a run. I'll report back what I get. – Corrosive Nov 24 '13 at 19:41
  • Thanks, that is exactly what I needed, it works perfectly under linux. – Corrosive Nov 24 '13 at 20:07