How to convert string with special control characters, like \'x1b', into a standard string?
<p>When I use python socket program, we give an option like:</p>

<pre class="lang-none prettyprint-override"><code>1) Input A to show your name
2) Input B to show your age
3) Input other to set your name

&gt;&gt;
</code></pre>

<p>When client types 'Too' + delete button + 'm', server receives 'Too\x1bm'.</p>

<p>How do I convert 'Too\x1bm' to 'Tom' in Python?</p>

<p>There may also be other control characters like 'move cursor' and 'tab'.</p>

<p>My first guess would be:</p>

<pre><code>line = 'Too\x1bm'

if '\x1b' in line:
    while True:
        index = line.find('\x1b')
        if index &gt; 0:
            line = line[:index - 1] + line[index + 1:]
        else:
            break

    line = line.replace('\x1b', '')
</code></pre>

python sockets