Removing Control characters

Terry Reedy tjreedy at
Mon Jan 6 19:30:14 CET 2003

"Amol Sonaikar" <amol at> wrote in message
news:mailman.1041872286.18579.python-list at
> Hi
> In your reply below you have used chr(8) to identify ^H. Can I use
> function chr(8) in if statement

chr(8) evaluates to the string '\x08'.  You can use it anywhere you
can use a string.

> for e.g. Similar like
> if line[i] == chr(8):
> i=i+1
> else:
> <  something >

Test things like this with the interactive interpreter.

>>> s='endswith^8\x08'
>>> if s[-1]==chr(8): print 'Hooray'

> Currently I am getting following error. What can be the correct
>     if str1[i] == chr(8)
>                        ^
> SyntaxError: invalid syntax

That looks fine.  The error might actually be on a previous line.

Terry J. Reedy

More information about the Python-list mailing list