I've got the following code
old_county_code = -1
old_placement_id = -1
placements = []
for row in raw_data: #raw_data is one line from the database retrieved by cursor.fetchall()
placement_id = row[1]
if placement_id != old_placement_id:
placement = Objects.placement()
placement.placement_id = placement_id
placements.append( placement )
country_code = row[3]
if old_county_code != country_code:
country = Objects.country()
country.country_id = country_code
placement.countries.append( country )
creative = Objects.creative( row[2], row[0], row[4], row[5], row[6], row[7] )
country.creatives.append( creative )
old_placement_id = placement_id
old_county_code = country_code
The object placement contains a list of countries which themselves contain a list of creatives. So, when I run this code I notice that each placement has the exact same number of country object contained in the list object placement.countries. Actually this cannot be the case. I think I did something wrong in my code but I don't know what.
This is the objects code
class placement(object):
placement_id = 0
countries = []
class country(object):
country_id = 0
creatives = []
class creative(object):
creative_id = 0
matching_id = 0
clicks = 0
impressions = 0
ctr = 0.0
rank = 0.0