How to parse VCard into a Python dictionary?

I am trying to figure out how to parse a VCard in a Python dictionary using VObject .

vobj=vobject.readOne(string) print vobj.behavior.knownChildren 

That is all I get:

 {'CATEGORIES': (0, None, None), 'ADR': (0, None, None), 'UID': (0, None, None), 'PHOTO': (0, None, None), 'LABEL': (0, None, None), 'VERSION': (1, 1, None), 'FN': (1, 1, None), 'ORG': (0, None, None), 'N': (1, 1, None), 'PRODID': (0, 1, None)} 

How can I populate the dictionary with VCard data?

+6
python vcf vcard
source share
1 answer

You do not want to look at behavior, you want to look at vobj . Behavior is a data structure that describes which children are required / expected and how to translate these children into appropriate Python data structures.

The vobj object is a component of vobject. Its content attribute is the vobject ContentLines dictionary and possibly Components, therefore

 vobject.contents 

will provide you with a dictionary of objects.

If you want to get a better understanding for a person about what has been analyzed, follow these steps:

 vobj.prettyPrint() 

To access individual children, do, for example:

 vobj.adr 
+9
source share

All Articles