简体   繁体   English

按类型解析 Vobject vcard 电话

[英]Parsing Vobject vcard telephones by type

I am trying to parse vCard Objects and i am having issues getting the different types of telephones or addresses ie home or work.我正在尝试解析 vCard 对象,但在获取不同类型的电话或地址(即家庭或工作地址)时遇到问题。 I can only get the first instance but not the second instance of phone.我只能得到第一个实例,而不能得到第二个电话实例。

TEL;TYPE=work,voice;VALUE=uri:tel:+11115551
TEL;TYPE=home,voice;VALUE=uri:tel:+14045551

contact = vobject.readOne(s, allowQP=True)
print contact.tel.type_param
print contact.tel

Both of those work but they only give me the first phone number.这两个都有效,但他们只给了我第一个电话号码。 I want to do something like below, but of course this gives me an error.我想做类似下面的事情,但这当然给了我一个错误。

print contact.tel.type_param.home
print contact.tel.work.value

What is the best way to access vCard objects by type?按类型访问 vCard 对象的最佳方法是什么?

Vobject is not documented very well. Vobject 没有很好地记录。 From the method doctring : """Return a child's value (the first, by default), or None."""从方法 doctring 中:"""返回子值(默认为第一个),或无。"""

So to fix it, i had to specify a childnumber other than Zero.所以要修复它,我必须指定一个非零的 childnumber。

 print contact.getChildValue('tel',default = None, childNumber = 0)
 print contact.getChildValue('tel',default = None, childNumber = 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM