Sep-25-2017, 09:44 AM
With the last example you've to pay attention about the order of the definition for page_sizes.
You can calculate the sizes also with a function, here a small example:
page_sizes = {(1189, 841):'A0', (841, 594):'A1', (594, 420):'A2', (420, 297):'A3', (297, 210):'A4'}The big numbers comes first, so this is the portrait orientation of this formats. If you accidentally exchange them (small number first, big number after), you'll never find the key.
You can calculate the sizes also with a function, here a small example:
from collections import OrderedDict def format_sizes(): formats_by_class = OrderedDict() formats_by_size = OrderedDict() w, h = 841, 1189 # definition of A0 for i in range(11): formats_by_class['A{}'.format(i)] = (h, w) formats_by_size[(h, w)] = 'A{}'.format(i) w, h = round(h / 2), w return formats_by_class, formats_by_sizeInstead of a normal dict, I use an OrderedDict, which keeps the order. So if you print the output, the order is preserved.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!