472,374 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 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
Thus, they won't be replaced.
Dotan Cohen


Skinheads are so tired of immigration, that they are going to move to
a country that don't accept immigrants!
Tommy Nordgren

Oct 17 '08 #1
0 1565

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

Similar topics

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.
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.
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...
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.
by: yochessyo | last post by:
Hi, Is there a way in VB.net to create or manipulate vcard? Thank you for your help.
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...
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....
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:...
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...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.