Python Forum
read text file and write into html with correct link
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read text file and write into html with correct link
#1
Do anyone know how to read a file, and write into html with the correct link page.

i have a file name test.txt, which contain:
www.google.com
www.cnn.com

If i write as below, it will not link to correct link page. Do anyone know why? What shall i correct, if i want to link correct place.

with open('test.txt') as f,open('out.html', 'w') as f_out:
    for line in f:
        line = line.strip()
        
        #print("<a href=",line ,"</a>","link")
        #print (line1)
       
        f_out.write('{}<br>'.format('<a href="line">Link </a>'))
        
        hyperlink_format = '<a href="{link}">{text}</a>'
        
	
How to i let it display on html which will have this two link.

i also try with this
f_out.write('{}<br>'.format('<a href="+line+">Link </a>'))
same
Reply


Messages In This Thread
read text file and write into html with correct link - by jacklee26 - Jul-25-2019, 10:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What does .flush do? How can I change this to write to the file? Pedroski55 3 208 Apr-22-2024, 01:15 PM
Last Post: snippsat
Question [SOLVED] Correct way to convert file from cp-1252 to utf-8? Winfried 8 877 Feb-29-2024, 12:30 AM
Last Post: Winfried
  Last record in file doesn't write to newline gonksoup 3 436 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,899 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  write to csv file problem jacksfrustration 11 1,546 Nov-09-2023, 01:56 PM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,468 Nov-09-2023, 10:56 AM
Last Post: mg24
Question Special Characters read-write Prisonfeed 1 627 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  Need to replace a string with a file (HTML file) tester_V 1 774 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  read file txt on my pc to telegram bot api Tupa 0 1,128 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,124 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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