Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get '\x01' to 1

Tags:

python

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

like image 430
steprobe Avatar asked Sep 11 '09 15:09

steprobe


2 Answers

ord("\x01") will return 1.

like image 170
sepp2k Avatar answered Sep 16 '22 14:09

sepp2k


Perhaps you are thinking of the ord function?

>>> ord("\x01")
1
>>> ord("\x02")
2
>>> ord("\x7f")
127
like image 37
gahooa Avatar answered Sep 19 '22 14:09

gahooa