Can Python fix vcard files?

Peter Pearson ppearson at nowhere.invalid
Tue Oct 14 16:54:56 CEST 2008


On Tue, 14 Oct 2008 03:23:37 +0200, Dotan Cohen <dotancohen at gmail.com> wrote:
> 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.

Google no farther; that's what this line does:
    for f in glob.glob('*.vcf'):

-- 
To email me, substitute nowhere->spamcop, invalid->net.



More information about the Python-list mailing list