We can simply use:
JavaScript
x
2
1
crc = struct.unpack('>i', data)
2
why do people write it like this:
JavaScript
1
2
1
(crc,) = struct.unpack('>i', data)
2
What does the comma mean?
Advertisement
Answer
The first variant returns a single-element tuple:
JavaScript
1
5
1
In [13]: crc = struct.unpack('>i', '0000')
2
3
In [14]: crc
4
Out[14]: (808464432,)
5
To get to the value, you have to write crc[0]
.
The second variant unpacks the tuple, enabling you to write crc
instead of crc[0]
:
JavaScript
1
5
1
In [15]: (crc,) = struct.unpack('>i', '0000')
2
3
In [16]: crc
4
Out[16]: 808464432
5