python字面量是什么_Python字节字面量具有非十六进制的额外字符,但会更改字符串的值...

I am used to the python byte literal syntax representing bytes as hex values such as b'\x7a' is the hex value 0x7a. I however have run into an issue that I don't know how it is working. I am using the ssl library for the first time and creating random values with ssl.RAND_bytes(...) It is returning strings with characters that alter the value (say when doing an int.from_bytes(...))

Example strings I have received:

b'\x12\x1f)\x8b\xe0\xd7LD'

b'\x808\x8a(\x02\xb3S\xc9\xabW_\n\xf3\xbb\x80o'

b'\xde\xef\x81%FMB=Ps'

b'9\x81\x90\xdc\xfa\x98\xbd\x1f^;'

What I don't understand are those non hex value characters, such as the 9 preceding the \x81 or the MB=Ps. I would like to understand what these extra values represent and how I can interpret them when debugging my code. I know python has no issue with these, it is me who is at a loss.

Note: I am on python3.3 on windows 7 64bit

解决方案

Byte array notation converts certain values to their textual representation:

>>> b'\x12\x41\x42'

b'\x12AB'

In this case the hex number 41 is the ASCII value for capital letter A.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值