擅长:python、mysql、java
<p>在Python2中,使用字符串文字:</p>
<pre><code>skt.send('\x12\r')
</code></pre>
<p>在Python 3中,使用字节文本或<a href="http://docs.python.org/dev/library/stdtypes.html#bytes.fromhex">^{<cd1>}</a>:</p>
<pre><code>skt.send(b'\x12\r')
skt.send(bytes.fromhex('12 0d'))
</code></pre>
<p>在这两种情况下,<a href="http://docs.python.org/dev/library/functions.html#bytearray">^{<cd2>}</a>类型都可能很有用,因为它是一种可变(可修改)类型,您可以用整数和字节文字构造它:</p>
<pre><code>skt.send(bytearray([0x02, 0x03, 0x00, 0x00, 0x05]))
</code></pre>