Python 2.7 在struct.unpack格式说明符中传递包含格式的变量

Python 2.7 在struct.unpack格式说明符中传递包含格式的变量,python-2.7,Python 2.7,我有一个字符串的长度,一个变量,比如 variable = len(another_variable) 是否有任何方法可以将此“变量”作为结构模块中的格式说明符传递。在正常情况下,它的工作原理是 list = sturct.unpack('2L', another_variable) 但我想要的是 list = struct.unpack('variable', another_variable) 或者我可以使用“变量”中存储的“另一个变量”的某些部分,我可以像这样使用它 list = s

我有一个字符串的长度,一个变量,比如

variable = len(another_variable)
是否有任何方法可以将此“变量”作为结构模块中的格式说明符传递。在正常情况下,它的工作原理是

list = sturct.unpack('2L', another_variable)
但我想要的是

list = struct.unpack('variable', another_variable)
或者我可以使用“变量”中存储的“另一个变量”的某些部分,我可以像这样使用它

list = stuct.unpack('L, variable', another_variable)

是否有任何方法可以在格式说明符中传递包含长度的变量,如果有,则如何以字符串或整数格式传递该变量。

找到了一种方法

struct.unpack(('<{0}L'.format(variable/4)), another_variable)
struct.unpack(('