0

I have following lines of code in my program and it executes fine, no issues but when i am trying to change the code slightly to print the output text in color and it doesnot work. I am sure it is a syntax issue, please if anybody can help, that would be great

from termcolor import colored, cprint
print("Name of the table:",table)
print("printing all the column names of this table:\n", df1_columns.columns)
print("count number of columns in this table: ",len(df1_columns.columns))

I changed the above to the following and throws an error

print(colored("print name of the table:"),table,'blue')                                                                                           
print(colored("print all the column names of this table:\n",df1_columns.columns,'blue')   
print(colored("print number of columns in this table: ",len(df1_columns.columns,'blue'))
skumar
  • 99
  • 1
  • 11
  • check documentation for `termcolor`. Other problem can be that not all terminals can display color. – furas Jul 07 '20 at 17:11
  • Do you problem with colors or you get error message ? If you get error then why you didn't show it in question. Don't expect that we will run code to see your error. – furas Jul 07 '20 at 17:13
  • BTW: in last line you have one `)` in wrong place - you have `blue` inside `len()` - `len(df1_columns.columns,'blue')` but it should be outside `len(df1_columns.columns), 'blue'`. But you should get error for this and you should show this error in question. – furas Jul 07 '20 at 17:15
  • Does this answer your question? [How to print colored text in Python?](https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-python) – Kate Orlova Jul 07 '20 at 17:16
  • print(colored("print name of the table:",'blue'),table) print(colored("print all the column names of this table:\n",'blue'),df1_columns.columns) print(colored("print number of columns in this table: ",'blue'),len(df1_columns.columns)) – skumar Jul 07 '20 at 20:27
  • Thanks everyone, I resolved the error, check the above comments for updates and it works fine now. – skumar Jul 07 '20 at 20:31

0 Answers0