Python字符串为整数值

Jas*_*son 1 python

我想知道如何将Python中的字符串转换为相应的整数值,如下所示:

>>>print WhateverFunctionDoesThis('\x41\x42')

>>>16706

我已经四处寻找,但一直没能找到一个简单的方法来做到这一点.

谢谢.

Joh*_*ooy 7

>>> import struct
>>> struct.unpack(">h",'\x41\x42')
(16706,)
>>> struct.unpack(">h",'\x41\x42')[0]
16706
Run Code Online (Sandbox Code Playgroud)

对于其他格式字符,请参阅文档