0
我在Python中很新,我想從多個傳感器的串行數據流中計算出串行數據。在流出的參數中,我想計算氣體的濃度。我第一次運行代碼(下面的修剪版本)時,它產生了一個類型錯誤,指出'float'不可迭代。所以我創建了一個名爲'my results = []'的列表,儘可能多地幫助博客建議,現在我在代碼的最後四行中的任何一行上都得到語法錯誤。任何方向都會有很大的幫助,謝謝。在python中使用串行數據列表進行迭代計算
from time import gmtime, strftime
import os
import msvcrt
import struct
import numpy as np
dataname = 'data.csv'
myresults = []
#preparing variables for calculations and plotting from string
with open(dataname, 'r') as csvfile: # open file for reading
for line in csvfile: # iterate over each line
parts = line.split(',') # split string on comma
value1 = float(parts[0]) # LAT
value2 = float(parts[2]) # LONG
value3 = float(parts[3]) # Height
value4 = float(parts[4]) # Volt
#Calculate concentration
Conc = (((2*value2)+(8*value3))*12)/value4
myresults.append(Conc)
print "Updated List: ", myresults
print Conc
quit()