擅长:python、mysql、java
<p>由于您的输入是使用Python的语法,因此出于某种原因(*),所以这里要做的就是调用<code>eval</code>:</p>
<pre><code>>>> r"b'\x12\x12'"
"b'\\x12\\x12'"
>>> eval(r"b'\x12\x12'")
'\x12\x12'
</code></pre>
<p>但是要小心,因为这可能是一个安全问题。<code>eval</code>将运行<em>任何</em>代码,因此您可能需要清理输入。在您的例子中,它很简单-只需检查您正在<code>eval</code>-ing的内容是否确实是您期望的格式的字符串。如果安全问题不是这里的问题,就不用麻烦了。在</p>
<p><strong>重编您的编辑</strong>:不过,<code>eval</code>是这里最简单的方法(如果没有<code>b''</code>,则添加<code>b''</code>)。当然,您也可以通过将每个<code>\xXX</code>转换为其实际值来手动执行此操作。在</p>
<hr/>
<p>(*)为什么,真的?对于数据表示格式,这似乎是一个奇怪的选择</p>