I have a dictionary like this in my django project which correspond to a config field:
{u'active': True,
u'alert': {u'item_sent': True,
u'emails': [u'test@test.com', u'test@test.com'],
u'job': u'500.00',
u'in_negative': False}}
How do I loop through each of the emails above and append '.fake' to the end of them? I was going for this – "test@test.com.fake"
I was doing this but it didn’t change the list items:
for p in practice:
email_count = len(p.config['alert']['emails'])
if email_count > 0:
print 'WE HAVE EMAILS'
i = 0
while i < email_count:
p.config['alert']['emails'][i] += '.fake'
print p.config['alert']['emails'][i]
i += 1
p.save()
Turns out I needed to assign p.config to a variable first before editing it. ‘P’ represents a practice object.