[Vobject] Creating a vcard with multiple addresses

Jeffrey Harris jeffrey at osafoundation.org
Fri Jan 2 12:41:40 CST 2009


Hi Jonathan,

> I've looked at the documentation and tests, but I'm not sure how to
> create a vcard with multiple addresses. I can parse a vcard with
> multiple addresses.

> v.add('adr')
> adrs = []
> adrs.append( vobject.vcard.Address( street='123 Main Street' ) )
> adrs.append( vobject.vcard.Address( street='1313 Mockingbird Lane' ) )
> v.adr_list = adrs

The vobject data structure is a little complicated.  Vobject expects a
tree of objects like this:

- Component
   - (Optional) Subcomponent
      - ContentLine
          - ContentLine has parameters, and a *value*
      - (Optional) Additional ContentLine

So, when you do v.add('adr'), you're adding an ADR ContentLine to v, a
VCARD Component.  What's going wrong here is you're setting v.adr_list
to a list of Address values but vobject expects it to be a list of
ContentLines with Address values.

Rather than setting adr_list directly, you can just call add() multiple
times.  So, you might do:

from vobject.vcard import Address
v.add('adr').value = Address(street='123 Main Street')
v.add('adr').value = Address(street='1313 Mockingbird Lane')

Hope that helps!
Jeffrey


More information about the VObject mailing list