use int()
to convert the string to an integer. Python doesn't have different fixed-width integers so you'll just get one type of thing out.
Then use struct
to pack the integer into a fixed width:
res = struct.pack("=B",i) ## uint8_t
res = struct.pack("=b",i) ## int8_t
res = struct.pack("=H",i) ## uint16_t
res = struct.pack("=h",i) ## int16_t
res = struct.pack("=I",i) ## uint32_t
res = struct.pack("=i",i) ## int32_t
res = struct.pack("=Q",i) ## uint64_t
res = struct.pack("=q",i) ## int64_t
res = struct.pack("=f",i) ## float
res = struct.pack("=d",i) ## double
struct
produces a byte-string containing the number in binary.
EDIT:
From the comments it sounds like you just want to convert the string (of decimal digits) into an integer. Just use int()
for that, however you won't get all the complicated overflow/underflow semantics of the specified types. You can't reproduce that in python, at least not without writing a whole lot of code.
I think if you want any more help you'll have to be more precise about what you want to achieve.