steprobe
steprobe

Reputation: 1699

How to get '\x01' to 1

I am getting this:

_format_ = "7c7sc"
print struct.unpack(self._format_, data)

gives

('\x7f', 'E', 'L', 'F', '\x01', '\x01', '\x01', '\x00\x00\x00\x00\x00\x00\x00', '\x00')

I want to take '\x01' and get 1 from it, i.e., convert to ``int. Any ideas? Thanks

Upvotes: 13

Views: 31560

Answers (2)

gahooa
gahooa

Reputation: 137492

Perhaps you are thinking of the ord function?

>>> ord("\x01")
1
>>> ord("\x02")
2
>>> ord("\x7f")
127

Upvotes: 4

sepp2k
sepp2k

Reputation: 370407

ord("\x01") will return 1.

Upvotes: 26

Related Questions