0

Ok so I have this code. I need to print attributes for each food in my list (created from a csv like this below

id,food,food_print,cal1,cal2,expi1999,expi2000,expi2001
1,bun,bun_bun,45.3434,199.32323,23.3333,45.4444,33.33333
2,burger,burger_bun,45.342343,200.34243,34.3333,0,9
3,pickle,pickle_seed,67.345454,34.3434,34,56,33
4,chicken,chicken_egg,44.34343,43.343343,43,434,34343

How do I print all values from meals to include all rows? Also when printing an object I get __main__.City object at 0x0000023B6FD552E0> How do I see what is in this? Inside the object?

import csv

class City(object):
    def __init__(self, food , foodprint, cal1, cal2, expi1999, expi2000, expi2001):
        self.food = food
        self.foodprint = foodprint
        self.cal1 = cal1
        self.cal2 = cal2
        self.expi1999 = expi1999
        self.expi2000 = expi2000
        self.expi2001 = expi2001

meals = []
with open('food.csv', 'r') as f:
    reader = csv.reader(f)
    foodies = list(reader)
    del foodies[0]

    print(foodies)

for rows in foodies:
    meals.append(City(rows[3],rows[4],rows[1],rows[2],rows[5],rows[6],rows[7]))
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
Sarukira
  • 13
  • 2
  • Your last line does not make sense to me. Your CSV is in the same order as your parameters of the City Class, yet it looks like you are trying to re-order them into the wrong variables ?? – ScottC Oct 24 '22 at 00:50
  • get the value of an attribute `instance.attribute_name` – cards Oct 24 '22 at 00:52
  • Also - this may answer your question: https://stackoverflow.com/questions/3992803/print-all-variables-in-a-class-python – ScottC Oct 24 '22 at 00:54

0 Answers0