[Vobject] About vobject's usage

Jeffrey Harris jeffrey at osafoundation.org
Tue Aug 15 18:23:09 CDT 2006


Hi Pablo,

> I'm using a .vcf file a friend of mine sent me. He uses OS X and this is
> the file where his contacts are stored. After doing the OS X ->
> GNU/Linux conversions (basically removing the CTRL-M and CTRL-@ from the
> file) I tried to load it using vobject:

I'm sorry, I don't understand what you mean.  There should be no
conversion when working with vcards, regardless of your operating
system.  Both Linux and OS X use line feeds for line endings, but vcards
require carriage-return + line-feed (Windows style, \r\n in Python) for
line endings.

> <code>
> # Yes, I know I have a rather weird path to voject.
> # It's just that the installer didn't place the library where
> # it should, apparently. So I had to create an __init__.py file
> # in ./vobject/ in order to make this work.

Did you run python setup.py install?  It looks like you've downloaded or
checked out a source package but haven't yet installed it.

> from vobject.src import vobject
> f = file("contacts.vcf")
> s = ""
> for x in f:
> 	s += x
> v = vobject.readOne(s)

What this code attempts to do is parse each line of contacts.vcf
separately.  Instead, you want to just do:

f = file("contacts.vcf")
v = vobject.readOne(f)

That will parse the first component it finds (spanning an arbitrary
number of lines) in contacts.vcf.

>     raise ParseError, 'Could not find BEGIN when trying to determine encoding'
> vobject.src.vobject.base.ParseError: 'Could not find BEGIN when trying
> to determine encoding'

This error would always happen given that you were parsing each line
separately, it may continue to happen if you're attempting to parse a
file you've received whose line endings you've changed.

> It's just a fresh file like the one anybody who has OS X could create.
> What am I doing wrong? I would also like to ask for more examples if
> possible. There's just one regarding vcards parsing, and reading the
> epydoc documentation didn't help in my case (as I said, I'm a newbie).

An excellent suggestion, I'll try to write more vcard examples.

> Of course, if this is not the right library for me I'd also like to hear
> that from you. And, if possible, it would be nice to see any other
> project that uses vobject's capabilities to understand how the parsing
> should be done.

Hopefully it works for you!  If these suggestions don't get it working
for you, let me know.

Sincerely,
Jeffrey


More information about the VObject mailing list