How to convert a string to its Base-10 representation?

base-conversion, python, string

Solution

This is a job for `struct`:

>>> s = 'YZ'
>>> struct.unpack('>Q', '\x00' * (8 - len(s)) + s)
(22874,)

Or a bit trickier:

>>> int(s.encode('hex'), 16)
22874

Problem

Is there any python module that would help me to convert a string into a 64-bit integer? (the maximum length of this string is 8 chars, so it should fit in a long). I would like to avoid having to write my own method. Example: ``` Input String Hex result (Base-10 Integer) 'Y' 59 89 'YZ' 59 5a 22874 ... ```

Original source