Python Forum
Saving python cmd output into a text file with colours
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving python cmd output into a text file with colours
#1
from colorama import Fore, Back, Style, init
import fpdf
from fpdf import FPDF


init()





paragraph = 'Whatever blame emerges! Its gasoline avoids the prison. The unlimited mania varies an exotic garage. A curtain farms? The sunrise fells an assorted companion around the jet.'


key_words = ['blame', 'avoids', 'unlimited', 'exotic']



def highlight(word):
    if word in key_words:
        return Fore.RED + str(word) + Fore.RESET
    
    else:
        return str(word)


textpara = paragraph.strip().split(' ')
colored_words = list(map(highlight, textpara))
final = " ".join(colored_words)
print (final)
I have created a code which highlight the keywords in a paragraph. I ran it in the cmd and it works fine (output is in the attachment). How do I save this output into file or PDF with colours highlighted so I don't have to re run the code again?

I tried to copy and paste the output into a text file but the colours did not show up

Thanks for the help

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
Saving python cmd output into a text file with colours - by kapilan15 - Jan-25-2019, 03:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replace a text/word in docx file using Python Devan 4 3,486 Oct-17-2023, 06:03 PM
Last Post: Devan
  save values permanently in python (perhaps not in a text file)? flash77 8 1,251 Jul-07-2023, 05:44 PM
Last Post: flash77
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,119 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,140 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Saving the times a script is run to a file or ... 3Pinter 7 1,420 Oct-19-2022, 05:38 PM
Last Post: 3Pinter
  Code Assistance needed in saving the file MithunT 0 822 Oct-09-2022, 03:50 PM
Last Post: MithunT
  Saving the print result in a text file Calli 8 1,823 Sep-25-2022, 06:38 PM
Last Post: snippsat
  Saving progress in a Python program to use later Led_Zeppelin 9 2,186 Sep-11-2022, 01:32 PM
Last Post: snippsat
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,710 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Trying to determine attachment file type before saving off.. cubangt 1 2,172 Feb-23-2022, 07:45 PM
Last Post: cubangt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020