2012-11-25 8 views
7

im usando vObject per creare una vCard. Tutto funziona bene, tranne che non posso aggiungere più numeri di telefono.Creazione di una vCard multi telefono utilizzando vObject

in questo momento sto facendo questo:

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 

Come sta funzionando come un valore chiave, il telefono di lavoro viene sovrascritto dal numero di fax.

Qualche idea su chi farlo nel modo giusto?

Grazie!

+0

Forse 'v.tel' ha bisogno di accedere come una lista o di un array, come 'v.tel [0] .type_param = 'WORK''. O forse 'v.add()' restituisce un oggetto, che è quello che dovresti assegnare a tipo_param e valore, come 'tel = v.add ('tel'); tel.type_param = 'WORK'' – Michael

risposta

10

Il metodo add() restituisce un oggetto specifico che può essere utilizzato per riempire in più di dati:

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()) 

uscita:

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 
Problemi correlati