擅长:python、mysql、java
<p>我想<code>''.join(r'\x{02:x}'.format(ord(c)) for c in mystring)</code>会起作用的。。。</p>
<pre><code>>>> mystring = "Hello World"
>>> print ''.join(r'\x{02:x}'.format(ord(c)) for c in mystring)
\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64
</code></pre>