Escapeism

Peter Otten __peter__ at web.de
Sat Sep 30 05:33:45 EDT 2006


Kay Schluehr wrote:

> Usually I struggle a short while with \ and either succeed or give up.
> Today I'm in a different mood and don't give up. So here is my
> question:
> 
> You have an unknown character string c such as '\n' , '\a' , '\7' etc.
> 
> How do you echo them using print?
> 
> print_str( c ) prints representation '\a' to stdout for c = '\a'
> print_str( c ) prints representation '\n' for c = '\n'
> ...
> 
> It is required that not a beep or a linebreak shall be printed.
> 
> First of all it has be remarked that it is impossible to a certain
> extent. That's because e.g. c = '\a' and c = '\7' do represent the same
> string but this ambiguity doesn't occur for many numbers. But lets
> weaken the requirement and fix a canonical representation in case of
> ambiguity. I'm still getting stuck here.

I don't understand the question. Wouldn't the canonical representation be
repr(c) or repr(c)[1:-1]?

Peter



More information about the Python-list mailing list