Let’s see here…
reshape, crop = {
1: ((1952, 3264), (1944, 3240)),
2: ((2480, 4128), (2464, 4100)),
}
This here is defining a dictionary with keys 1
and 2
. Attached to each key is a tuple of tuples. I believe there are more entries in the real code, going by the comma on the last item. However, most of this object gets lost to garbage collection. The tuple assignment to reshape
and crop
will result in only the keys being stored. So the result of this thing is the same as:
reshape = 1
crop = 2
Interesting if useless. Next…
offset = {1: 6404096, 2: 10270208,}[ver]
So this here defines another dictionary with keys 1
and 2
and long integer values associated with them. It then indexes this dictionary with ver
and assigns the value at this index to offset
. Since ver
isn’t defined yet, this would really result in an exception. Let’s say that the following code was given before the previous:
#where ver is defined as a dictionary
ver = {
'RP_ov5647': 1,
'RP_imx219': 2,
}[camera.exif_tags['IFD0.Model']]
Here we have yet another dictionary. This time the keys are 'RP_ov5647'
and 'RP_imx219'
with values of 1
and 2
. This dictionary is indexed with a value of camera.exif_tags['IFD0.Model']
. Assuming that camera.exif_tags
is an object with keyed indexes, one of the indexes is 'IFD0.Model'
and the resulting value is either 'RP_ov5647'
or 'RP_imx219'
, ver
will be assigned either 1
or 2
.
So that 1 or 2 will be used to index our above offset value resulting in offset being assigned either 6404096
or 10270208
In short, it’s all a syntactically valid bunch of nothing. Thanks for sharing.
4
solved Python data type, what kind of data structure it is? [closed]