Sep-26-2017, 04:09 PM
In snippet #3 you're using tuples. I haven't seen it.
What I meant with my first post, is that you have to pay attention of the order in page_sizes.
Your example from #3 with exchanged height and width in page_sizes:
Output:In [2]: page_info(1189, 1)
Out[2]: {'orientation': 'Portrait', 'size': 'Unknown'}
Then the output is right.What I meant with my first post, is that you have to pay attention of the order in page_sizes.
Quote:With the last example you've to pay attention about the order of the definition for page_sizes.
Your example from #3 with exchanged height and width in page_sizes:
def page_info(height, width): if height == width: p_size, p_orientation = 'Unknown', 'Square' else: p_dimensions = tuple(sorted([height, width], reverse=True)) page_sizes = {(841, 1189):'A0', (841, 594):'A1', (594, 420):'A2', (420, 297):'A3', (210, 297):'A4'} page_orientations = {True:'Portrait', False:'Landscape'} p_size = page_sizes.get(p_dimensions, 'Unknown') p_orientation = page_orientations[height>width] return {'size':p_size, 'orientation':p_orientation} for height, width in ((1189, 841), (210, 297), (200, 100), (300, 300)): p_info = page_info(height, width) print("Page size is {size}, orientation is {orientation}".format(**p_info))
Output:Page size is Unknown, orientation is Portrait
Page size is Unknown, orientation is Landscape
Page size is Unknown, orientation is Portrait
Page size is Unknown, orientation is Square
Instead of writing 10 replies, I'll post next time directly how to break your code example ;-)
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!