I have a py script which amongst other things parses a value from a HTML table using BeautifulSoup.
The value which is being returned (outTempReal) seems to have some whitespace after the value. I know this due to the print I use...
print "Temp 1 =", avgtemperatures[0],
print "Temp 2 =", avgtemperatures[1],
print "Temp 3 =", avgtemperatures[2],
print "Temp 4 =", avgtemperatures[3],
print "Temp 5 =", avgtemperatures[4],
print "Outside Temp =", outTempReal,
print "METAR Temp =", currentTemp,
print "Plant Room Temp =", avgtemperatures[5],
print "Flow Temp =", avgtemperatures[6],
print "Return Temp =", avgtemperatures[7]
Which returns the following...
Temp 1 = 79.625 Temp 2 = 79.1456666667 Temp 3 = 31.229 Temp 4 = 28.125 Temp 5 = 27.2706666667 Outside Temp = 4.8 METAR Temp = 5 Plant Room Temp = 16.7913333333 Flow Temp = 13.875 Return Temp = 18.312
You can see that after the Outside Temp = 4.8 there is whitespace before the next print value.
This is the code used to get the value in the first place...
table = soup.find('table')
for row in table.findAll('tr')[1:]:
col = row.findAll('td')
if len(col) >= 2:
time = col[1].string
temp = col[2].string
outTempReal = re.sub(r'[^0-9\-\d.\s+]',' ', temp)
I have tried the following two methods to remove the whitespace but no joy...
outTempReal.strip()
re.sub('\s+',' ',outTempReal)
I really need this value to be just the decimal number because it is used to update a RRD.
Can anyone help?