Can Python fix vcard files?

Dotan Cohen dotancohen at gmail.com
Mon Oct 13 21:23:37 EDT 2008


2008/10/14  <skip at pobox.com>:
>
>    Dotan> Can Python go through a directory of files and replace each
>    Dotan> instance of "newline-space" with nothing?
>
> Sure.  Something like (*completely* untested, so caveat emptor):
>
>    import glob
>    import os
>
>    for f in glob.glob('*.vcf'):
>        # corrupt data
>        uncooked = open(f, 'rb').read()
>        # fix it
>        cooked = uncooked.replace('\n ', '')
>        # backup original file for safety
>        os.rename(f, '%s.orig' % f)
>        # and save it
>        open(f, 'wb').write(cooked)
>

Thanks, that's easier than I thought! I am sure with some googling I
will discover how to loop through all the files in a directory. One
question, though, is that code unicode-safe in the event that there
are unicode characters in there?

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

ä-ö-ü-ß-Ä-Ö-Ü


More information about the Python-list mailing list