Help me on Backspace please

Craig Radcliffe chradcliffe at gmail.com
Thu Jun 26 17:58:26 EDT 2008


Something like this might do the trick:

import re
f  = open("file.txt")
old_text = f.readlines()
f.close()
new_text = [re.sub(r'.\b', '', i) for i in old_text]
f = open("file_modified.txt", "w")
f.writelines(new_text)

I don't know how necessary the separate read and writes are, but it'll be
good for a start. At any rate, you'll want to look at the
re<http://docs.python.org/lib/module-re.html>module.

On Thu, Jun 26, 2008 at 16:32, <cakomo at gmail.com> wrote:

> Hi
> I am a beginner on Python and have a problem..
>
> I have text file and reading it line by line and there are backspace
> characters in it like '\b' or anything you want like "#".  I want to
> replace these chars. with Backspace action. I mean deleting the
> previous char. and the \b char also. and writing all cleaned text to a
> file again.
>
> How can I do that.
>
> Thanks..
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080626/f2b748c1/attachment-0001.html>


More information about the Python-list mailing list