如何在Python 3中将原始的十六进制字节写入stdout? [英] How to write a raw hex byte to stdout in Python 3?
本文介绍了如何在Python 3中将原始的十六进制字节写入stdout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你如何让Python 3输出原始的十六进制字节?我想输出十六进制 0xAA
。
如果我使用 print(0xAA)
,我得到了ASCII'170'。
解决方案
解决方案是首先创建一个<$ c
$ p $ $ $ $ $ $ $ $ $ $ $ $ $ b
然后使用缓冲写入器输出 stdout
/ p>
sys.stdout.buffer.write(x)
How do you get Python 3 to output raw hexadecimal byte? I want to output the hex 0xAA
.
If I use print(0xAA)
, I get the ASCII '170'.
解决方案
The solution was to first create a bytes
object:
x = bytes.fromhex('AA')
And then output this to stdout
using the buffered writer
sys.stdout.buffer.write(x)
这篇关于如何在Python 3中将原始的十六进制字节写入stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文