Create a business card for multiple phones with vObject

im using vObject to create a vCard. Everything works well, except that I cannot add multiple phone numbers.

Now I am doing this:

v.add('tel') v.tel.type_param = 'WORK' v.tel.value = employee.office_phone v.add('tel') v.tel.type_param = 'FAX' v.tel.value = employee.fax 

Since it works as a key value, the work phone is overwritten with a fax number.

Any idea on who needs this?

Thanks!

+7
source share
1 answer

The add() method returns a specific object that can be used to populate more data:

 import vobject j = vobject.vCard() o = j.add('fn') o.value = "Meiner Einer" o = j.add('n') o.value = vobject.vcard.Name( family='Einer', given='Meiner' ) o = j.add('tel') o.type_param = "cell" o.value = '+321 987 654321' o = j.add('tel') o.type_param = "work" o.value = '+01 88 77 66 55' o = j.add('tel') o.type_param = "home" o.value = '+49 181 99 00 00 00' print(j.serialize()) 

Output:

 BEGIN:VCARD VERSION:3.0 FN:Meiner Einer N:Einer;Meiner;;; TEL;TYPE=cell:+321 987 654321 TEL;TYPE=work:+01 88 77 66 55 TEL;TYPE=home:+49 181 99 00 00 00 END:VCARD 
+10
source

All Articles