when you do
You can go further and instead of list use namedtuple (these are fixed values, fixed-len lists, right?). This is short of creating custom class, but makes it much better, no magic numbers (e.g. I don't know what
In the example I stick to list of devices but implement devices as namedtuple
selected_device = (device_list[x])
, selected_device
is just a string, it's not the list as you think. Now, there is a way to do what you want, but it is plainly WRONG (you don't create names dynamically but it's the same problem). You should use a proper structure. in this case - a dict looks OK. The key would be the thermistor name, e.g. "0.1K1A"
and the value will be the list - [1.942952*10**-3, 2.989769*10**-4, 3.504383*10**-7]
You can go further and instead of list use namedtuple (these are fixed values, fixed-len lists, right?). This is short of creating custom class, but makes it much better, no magic numbers (e.g. I don't know what
1.942952*10**-3
represents).In the example I stick to list of devices but implement devices as namedtuple
from collections import namedtuple Device = namedtuple('Device', 'part_no coef_a coef_b coef_c') devices = [ Device('0.1K1A', 1.942952*10**-3, 2.989769*10**-4, 3.504383*10**-7), # 0.1K1A Device('0.3K1A', 1.627660*10**-3, 2.933316*10**-4, 2.870016*10**-7), # 0.3K1A Device('1K2A', 1.373168*10**-3, 2.772261*10**-4, 1.997412*10**-7), # 1K2A Device('1K7A', 1.446059*10**-3, 2.683626*10**-4, 1.643561*10**-7), # 1K7A Device('2K3A', 1.498872*10**-3, 2.379047*10**-4, 1.066953*10**-7), # 2K3A Device('2.K3A', 1.471388*10**-3, 2.376138*10**-4, 1.051058*10**-7), # 2.2K3A Device('3K3A', 1.405027*10**-3, 2.369386*10**-4, 1.012660*10**-7), # 3K3A Device('5K3A', 1.287450*10**-3, 2.357394*10**-4, 9.505200*10**-8), # 5K3A Device('10K3A', 1.129241*10**-3, 2.341077*10**-4, 8.775468*10**-8), # 10K3A Device('10K4A', 1.028444*10**-3, 2.392435*10**-4, 1.562216*10**-7), # 10K4A Device('30K5A', 9.331754*10**-4, 2.213978*10**-4, 1.263817*10**-7), # 30K5A Device('30K6A', 1.068981*10**-3, 2.120700*10**-4, 9.019537*10**-8), # 30K6A Device('50K6A', 9.657154*10**-4, 2.106840*10**-4, 8.585481*10**-8), # 50K6A Device('100K6A', 8.271111*10**-4, 2.088020*10**-4, 8.059200*10**-8), # 100K6A Device('1M9A', 7.402387*10**-4, 1.760865*10**-4, 6.865999*10**-8)] # 1M9A for idx, device in enumerate(devices, start=1): print(f'{idx: >2d}.{device.part_no}') user_choice = int(input(f'Select device (1-{len(devices)}): ')) - 1 device = devices[user_choice] print(device) print(device.part_no) print(device.coef_b)
Output: 1.0.1K1A
2.0.3K1A
3.1K2A
4.1K7A
5.2K3A
6.2.K3A
7.3K3A
8.5K3A
9.10K3A
10.10K4A
11.30K5A
12.30K6A
13.50K6A
14.100K6A
15.1M9A
Select device (1-15): 13
Device(part_no='50K6A', coef_a=0.0009657154, coef_b=0.00021068400000000002, coef_c=8.585481e-08)
50K6A
0.00021068400000000002
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs