Is it possible to make simple variables from dictionaries? Something like:
dct = {'key1': val1, 'key2': val2}
should be turned to the variables key1 and key2, so that
print key1
val1
print key2
val2
Why it may be important? In my case because of readability.
I'm implementing multiple design standards in my project, to design well, stuff.
To separate the design code from the physical object being calculated I use interface functions, that get some of the objects that describe the physical object, extract the data needed and return these as dictionaries to be used in the functions doing the standard-based calculation.
Using dictionaries for this makes passing arguments easy (positional arguments would be a nightmare, kwargs yields the same problem that I have now), but results unreadable code when it comes to implementing the formulae in the standard.
An example, a rather simple formula:
_ret = (d['Da'] * d['p']) / (20 * (d['K'] / d['S']) * d['v'] + d['p']) + d['c1'] + d['c2']
vs.
_ret = (Da * p) / (20 * (K / S) * v + p) + c1 + c2
Another solution would be to make a class instead of the dict, using type(). That would result in something like:
_ret = (c.Da * c.p) / (20 * (c.K / c.S) * c.v + c.p) + c.c1 + c.c2
This is better, but not by much.
To avoid the visual noise, now I simply define new variables from all key-value pairs passed from the interface function, like
Da = d['Da']
p = d['p']
etc.
This solution is surely not the best, although it leads to easy to read code - but I couldn't come up with a 'magical' one. Do you have any suggestions how to do this transformation simply?