[Vobject] how to parse each part (street, postal code, country etc...) of an addresses with vobject?
Adam Tauno Williams
awilliam at opengroupware.us
Tue Jan 12 07:00:54 CST 2010
On Mon, 2010-01-11 at 17:28 +0800, Frederic Vautard wrote:
> Hi,
> I am using Vobject to parse vcards. I have an issue to access each
> part of an address:
> Here is my Vcard:
> BEGIN:VCARD
> VERSION:3.0
> N:Gump;Forrest
> FN:Forrest Gump
> ORG:Bubba Gump Shrimp Co.
> TITLE:Shrimp Man
> TEL;TYPE=WORK,VOICE:(111) 555-1212
> TEL;TYPE=HOME,VOICE:(404) 555-1212
> ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of
> America
> LABEL;TYPE=WORK:100 Waters Edge\nBaytown, LA 30314\nUnited States of
> America
> ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of
> America
> LABEL;TYPE=HOME:42 Plantation St.\nBaytown, LA 30314\nUnited States of
> America
> EMAIL;TYPE=PREF,INTERNET:forrestgump at example.com
> REV:20080424T195243Z
> END:VCARD
> I can access the first address by typing:
> >>> print vcard.adr_list[0]
> <ADR{u'TYPE': [u'WORK']}100 Waters Edge
> Baytown, LA 30314
> United States of America>
> I can just get the value of this address from:
> >>> print vcard.adr_list[0].value
> 100 Waters Edge
> Baytown, LA 30314
> United States of America
> Or I can get the fields separated by a ";" by using:
> >>> print vcard.adr_list[0].serialize()
> ADR;TYPE=WORK:;;100 Waters Edge;Baytown;LA;30314;United States of
> America
> However I have to parse this output to get each field. Is there
> already a way in Vobject to get each part of the address
> independently ? (street, region, postal code, country....) ?
If you find some 'elegant' way to do this please post it. I will be
having to parse vCards soon - some example code would be greatly
appreciated.
More information about the VObject
mailing list