473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 1656

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ed | last post by:
What's the easiest way of developing an address book using ASP that is compatible with vCard? I'd like to be able to do this without 3rd party components. Thanks.
3
by: scott | last post by:
Anyone have a link to syntax that could create an outlook vcard file format? all examples i find are for doing it inside outlook with .net. i'm just looking for an ASP solution.
1
by: Jason Karns | last post by:
Does anyone know of any stylesheets out that are already built to transform the RDF vCard format (XML) to regular vCard file format (.vcf)? I've searched google for a while now and haven't found...
4
by: localhost | last post by:
Looking for some sample code to emit a vcard (for Outlook) directly to a web browser after clicking on a button. Thanks.
3
by: yochessyo | last post by:
Hi, Is there a way in VB.net to create or manipulate vcard? Thank you for your help.
4
by: R Wood | last post by:
Greetings - A recent Perl experiment hasn't turned out so well, which has piqued my interest in Python. The project is this: take a Vcard file exported from Apple's Addressbook and use a...
2
by: eloi-ribeiro.blogspot.com | last post by:
Hi everyone, I would like to use a python script to export (save as...) all my contacts in Evolution to VCard format (.vcf). I am a beginner so I don't knock how to use evolution-python module....
8
by: Dotan Cohen | last post by:
KDE's Kontact PIM breaks quoted-printable vcard files because it linebreaks in the middle of a word. Take this text for example:...
0
by: Terry Reedy | last post by:
Dotan Cohen wrote: I believe that particular find/replace should be safe even if other bytes represent encoded unicode. In Python3, if you want to do more, and if you open in text mode, the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.