Help me on Backspace please

2008-06-26 Thread cakomo
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


Re: Help me on Backspace please

2008-06-27 Thread cakomo
On Jun 27, 3:06 am, John Machin <[EMAIL PROTECTED]> wrote:
> On Jun 27, 6:32 am, [EMAIL PROTECTED] 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.
>
> I haven't seen anything like that for ... ummm, a very long time. Used
> for bolding and making up your own characters on a daisy-wheel
> printer. Where did you get the file from?
>
> If there are no cases of multiple adjacent backspaces (e.g. "blahfoo\b
> \b\bblah") you can do:
>    new_line = re.sub(r'.\x08', old_line, '')
>
> Note: using \x08 for backspace instead of \b to avoid having to worry
> about how many \ to use in the regex :-)
>
> Otherwise you would need to do something like
>    while True:
>       new_line = re.sub(r'[^\x08]\x08', '', old_line)
>       if new_line == old_line: break
>       old_line = new_line
>
> And if you were paranoid, you might test for any remaining stray
> backspaces, just in case the line contains "illegal" things like
> "\bfoo" or "foo\b\b\b\b" etc.
>
> Cheers,
> John

Thanks John
I will try it but, do you think regex replacement gonna erase the
prev. char.?

Thanks  a lot for your reply.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help me on Backspace please

2008-06-27 Thread cakomo
On Jun 27, 11:09 am, John Machin <[EMAIL PROTECTED]> wrote:
> On Jun 27, 5:27 pm, cakomo <[EMAIL PROTECTED]> wrote:
>
> > On Jun 27, 3:06 am, John Machin <[EMAIL PROTECTED]> wrote:
> > >    new_line = re.sub(r'.\x08', old_line, '')
>
> > >       new_line = re.sub(r'[^\x08]\x08', '', old_line)
>
> > Thanks John
> > I will try it but, do you think regex replacement gonna erase the
> > prev. char.?
>
> Yair i think its gunna y do u ask?

Sorry John

Did i said i am a newbie still trying to figure out. But regex
statement is really  what i want. Thank you very much :)
--
http://mail.python.org/mailman/listinfo/python-list