LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-24-2009, 02:49 PM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Colored output in Python


I want my Python script to have an option to color its output, so I decided to try ANSI escape codes:

Code:
print '\e[1;31mColor Text\e[0m'
print '\u001b[1;31mColor Text\u001b[0m'
But instead of coloring the text, the escape codes got printed out literally:

Code:
\e[1;31mColor Text\e[0m
\u001b[1;31mColor Text\u001b[0m
I thought that '\e' is the standard code for escape, and I read that '\uXXXX' is a hex unicode character in Python, but none worked.

I know that the escape codes work because I even have my bash prompt colored with them, but it seems like I just can't get Python to output an escape character.

What should I do?
 
Old 12-24-2009, 05:36 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
http://stackoverflow.com/questions/2...s-using-python
 
Old 12-24-2009, 08:01 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
It works!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting colored text output file using C ibabhelix Programming 2 11-04-2009 02:53 AM
Python serial output seems strange edM Programming 2 04-27-2009 04:54 AM
python shell doesn't run idle output me_lax Linux - Newbie 3 09-13-2008 11:55 PM
python read output from seperate script? bendeco13 Programming 1 02-01-2005 10:38 PM


All times are GMT -5. The time now is 11:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration