Python Forum
code for CSV file to html file without pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code for CSV file to html file without pandas
#1
Need to write information into csv and then transfer this information to HTML file.
Reply
#2
There are many other libraries PyPi this if don't want to use Pandas eg CSVtoTable
If doing as training i can write a start example of one way it could be done.
Output:
# test.csv Identifier,First name,Last name 901242,Rachel,Booker 207074,Laura,Grey 408129,Craig,Johnson
import csv

with open("test.csv") as csvfile:
    reader = csv.DictReader(csvfile, delimiter=",")
    for row in reader:
        print("<tr>")
        td = '<td>'
        for fn in reader.fieldnames:
            print(f"{td:>6}{row[fn]}</td>")
        print("</tr>")
Output:
<tr> <td>901242</td> <td>Rachel</td> <td>Booker</td> </tr> <tr> <td>207074</td> <td>Laura</td> <td>Grey</td> </tr> <tr> <td>408129</td> <td>Craig</td> <td>Johnson</td> </tr>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  file open "file not found error" shanoger 8 946 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Need to replace a string with a file (HTML file) tester_V 1 699 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 874 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,048 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 878 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,071 Dec-15-2022, 04:32 PM
Last Post: Larz60+
Photo String comparison in a csv file in Python Pandas fleafy 2 1,110 Nov-18-2022, 09:38 PM
Last Post: fleafy
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 698 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  Code Assistance needed in saving the file MithunT 0 785 Oct-09-2022, 03:50 PM
Last Post: MithunT
Photo Making Zip file of a file and Directory Nasir 2 985 Oct-07-2022, 02:01 PM
Last Post: Nasir

Forum Jump:

User Panel Messages

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