I have got a very nasty piece of code i would like to refactor but i’ve because its getting totaly unreadable.
for region in feed['config']['regions']:
if region['region'] == region_name:
for instance_type in region['instanceTypes']:
if instance_type['type'] == instance_type_name:
for instance_size in instance_type['sizes']:
if instance_size['size'] == instance_size_name:
for platform in instance_size['valueColumns']:
if platform['name'] == platform_name:
prices = platform['prices']
assert prices.keys() == ['USD']
return decimal.Decimal(prices['USD'])
assert False, "Failed to determine price for instance with region=%r, type=%r, size=%r, platform=%r" % \
(region_name, instance_type_name, instance_size_name, platform_name)
I’ve tought about using functions with each loop or if statement but that will give me a load of functions.
Are there beter solutions?
or one step farther: