Removing Control characters

Terry Reedy tjreedy at udel.edu
Mon Jan 6 13:30:14 EST 2003


"Amol Sonaikar" <amol at kenati.com> wrote in message
news:mailman.1041872286.18579.python-list at python.org...
> Hi
>
> In your reply below you have used chr(8) to identify ^H. Can I use
same
> 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'
...
Hooray

> Currently I am getting following error. What can be the correct
syntax
>
>     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