We will start by converting the planets data into a CSV file.
- This will be performed using csv. The following code writes the planets data to a CSV file (the code is in03/create_csv.py):
import csvfrom get_planet_data import get_planet_dataplanets = get_planet_data()with open('../../www/planets.csv', 'w+', newline='') as csvFile: writer = csv.writer(csvFile) writer.writerow(['Name', 'Mass', 'Radius', 'Description', 'MoreInfo'])for planet in planets: writer.writerow([planet['Name'], planet['Mass'],planet['Radius'], planet['Description'], planet['MoreInfo']])
- The output file is put into the www folder of our project. Examining it we see the following content::
Name,Mass,Radius,Description,MoreInfo Mercury,0.330,4879,Named ...