How do I parse a VCard to a Python dictionary?

前端 未结 1 1192
萌比男神i
萌比男神i 2021-02-09 17:15

I\'m trying to figure out how to parse a VCard to a Python dictionary using VObject.

vobj=vobject.readOne(string)
print vobj.behavior.knownChildren
1条回答
  •  花落未央
    2021-02-09 17:35

    You don't want to look at the behavior, you want to look at vobj itself. The behavior is a data structure describing what children are required/expected, and how to translate those children into appropriate Python data structures.

    The vobj object is a vobject Component. Its contents attribute is a dictionary of vobject ContentLines and possibly Components, so

    vobject.contents
    

    will give you a dictionary of objects.

    If you want a more human readable view of what was parsed, do:

    vobj.prettyPrint()
    

    To access individual children, do, for instance:

    vobj.adr
    

    0 讨论(0)
提交回复
热议问题