Forum Archive

Add email to contacts

dejan56

Hi,
I am new to both Python and Pythonista. I am trying to create code to deduplicate contacts on iPhone.
However, I am not able to add email to Contacts.

import contacts

people = contacts.get_all_people()

print people[0].full_name
people[0].email.append((u'$!!$', u'test@test.com'))
contacts.save()

Why is this email not showing up in iPad Contacts?
Regards,
Dejan

omz

you have to re-assign the email attribute of the Person object. Modifying the list in-place has no effect, because the Person object cannot detect changes in that list (it's just a snapshot copy).

Try something like this:

import contacts
people = contacts.get_all_people()
print people[0].full_name

emails = people[0].email
emails.append((u'$!<Other>!$', u'test@test.com'))
people[0].email = emails # !!!

contacts.save()
nisitha53

wow really great coding email append thanks to shared this