Jul-18-2022, 01:26 PM
Hi,
The response from a web form fills an array. Its content may average from empty to several strings.
I need to extract data from said strings so I can work with it.
I came out with the following code but I'm sure it can be improved.
I appreciate some opinion/improvement.
TIA
The response from a web form fills an array. Its content may average from empty to several strings.
I need to extract data from said strings so I can work with it.
I came out with the following code but I'm sure it can be improved.
I appreciate some opinion/improvement.
TIA
import re soil1 = 0 soil2 = 0 checkbox1 = 0 checkbox2 = 0 para_array = ['s1=2.67', 's2=34', 'p1=1', 'p2=1'] for i in range(len(para_array)): if para_array[i].find('s1=') > -1: a = para_array[i] soil1 = re.sub('s1=', '', a) if para_array[i].find('s2=') > -1: a = para_array[i] soil2 = re.sub('s2=', '', a) if para_array[i].find('p1=') > -1: a = para_array[i] checkbox1 = re.sub('p1=', '', a) if para_array[i].find('p2=') > -1: a = para_array[i] checkbox2 = re.sub('p2=', '', a) print(soil1, soil2, checkbox1, checkbox2)