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
  How to write variable in a python file then import it in another python file? tatahuft 4 882 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Read TXT file in Pandas and save to Parquet zinho 2 1,210 Sep-15-2024, 06:14 PM
Last Post: zinho
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,037 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 847 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  docx file to pandas dataframe/excel iitip92 1 2,431 Jun-27-2024, 05:28 AM
Last Post: Pedroski55
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 6,201 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  file open "file not found error" shanoger 8 6,219 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Need to replace a string with a file (HTML file) tester_V 1 1,871 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 2,091 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 2,077 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone

Forum Jump:

User Panel Messages

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