469,590 Members | 2,500 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

Re: Can Python fix vcard files?


On Oct 14, 2008, at 3:23 AM, Dotan Cohen wrote:
2008/10/14 <sk**@pobox.com>:
>>
DotanCan Python go through a directory of files and replace each
Dotaninstance 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?
Sure! all the bytes in multibyte UTF-8 characters are above 128 in
value.
Thus, they won't be replaced.
--
Dotan Cohen

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

ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list
----------------------------------
Skinheads are so tired of immigration, that they are going to move to
a country that don't accept immigrants!
Tommy Nordgren
to************@comhem.se

Oct 17 '08 #1
0 1443

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ed | last post: by
3 posts views Thread by scott | last post: by
1 post views Thread by Jason Karns | last post: by
4 posts views Thread by localhost | last post: by
3 posts views Thread by yochessyo | last post: by
4 posts views Thread by R Wood | last post: by
2 posts views Thread by eloi-ribeiro.blogspot.com | last post: by
8 posts views Thread by Dotan Cohen | last post: by
reply views Thread by Terry Reedy | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.