Welcome folks today in this blog post we will be
converting csv file to html table using prettytable library full tutorial for beginners. All the source code of the tutorial will be given below.
In order to get started we need to install the following library
pip install prettytable
Just install this
prettytable library and now create a
app.py file and copy paste the following code
from prettytable import PrettyTable # open csv file a = open("users.csv", 'r') # read the csv file a = a.readlines() # Seperating the Headers l1 = a l1 = l1.split(',') # headers for table t = PrettyTable([l1, l1]) # Adding the data for i in range(1, len(a)) : t.add_row(a[i].split(',')) code = t.get_html_string() html_file = open('Table.html', 'w') html_file = html_file.write(code)
Now create a
users.csv file inside your root directory of your project like this
name,age gautam,23 kane,30
And if you run this script by executing the below command
and now a
Table.html file will be created in the root folder of your project like below.