Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4824

Python • Re: list/dict error - not understanding

$
0
0

Code:

if parts[0] == FIRST_LABEL:results = {}results[parts[0]] = parts[1]

First you read a line and put the string value into line.
From line you split with the equal to the list parts.
parts[0] will contains the name of the value
parts[1] will contains the value

then you check if the name of the value , parts[0], is the FIRST_LABEL
if yes then your create an empty dictionary results and add an item into it
results[parts[0]]=parts[1]. parts[0] is the name of the vale and parts[1] is the value

Then the rest of the code is quite bad ......

since results is a dictionary which hold all the data you should at least include all items in the dictionary first.

for what I see only results[HOT_FLUID_TEMP] is set!

So where did you set the three other datas.

B.T.W. dictionary could not be indexes. results[3] is invalid.

Statistics: Posted by danjperron — Wed Apr 17, 2024 12:53 am



Viewing all articles
Browse latest Browse all 4824

Trending Articles