Best way to convert sequence of bytes to long integer

Mark Dickinson dickinsm at
Wed Jan 20 15:18:55 CET 2010

On Jan 20, 7:36 am, Steven D'Aprano <st... at REMOVE-THIS-> wrote:
> I have a byte string (Python 2.x string), e.g.:
> s = "g%$f yg\n1\05"
> assert len(s) == 10
> I wish to convert it to a long integer, treating it as base-256.

By the way, are you willing to divulge what you're using this
functionality for?  When trying to hack out the API for int.to_bytes
and int.from_bytes on the mailing list and bug tracker, some of the
discussion about use-cases seemed a little too much like guesswork;
I'd be curious to find out about real-life use-cases.


More information about the Python-list mailing list