Python错误:不支持的操作数类型 - :' float'和' NoneType'

时间:2014-08-15 14:50:57

标签: python syntax-error operand

我的代码应该相互读取和减去两个数据列表。为什么我收到此错误,我该如何解决?

以下是完整错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "spectra.py", line 32, in SpectraTest
    subt = map(sub, flux, flux1)
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'

以下是代码:

import csv

def SpectraTest():
    wave_num = []
    flux = []
    wave_num1=[]
    flux1 = []
    with open ("H20_Glass.CSV", "rb") as csvfile:
        datareader= csv.reader(csvfile, delimiter = ",")
        for row in datareader:
            tempdata = row
            wn = tempdata[0]
            f1 = tempdata [1]
            wn = eval(wn)
            f1 = eval(f1)
            wave_num.append(wn)
            flux.append(f1)

    with open ("blankGlass.CSV", "rb") as csvfile:
        datareader= csv.reader(csvfile, delimiter = ",")
        for row in datareader:
            tempdata1 = row
            wn1 = tempdata1[0]
            f2 = tempdata1[1]
            wn1 = eval(wn1)
            f2 = eval(f2)
            wave_num1.append(wn1)
            flux1.append(f2)
        map(float, flux1)
        map(float, flux)
        from operator import sub
        subt = map(sub, flux, flux1)
        wave_num1.reverse()
        wave_num.reverse()
        print("Number of wave numbers " + str(len(wave_num1)))
        print("Number of flux numbers = "+ str(len(flux1)))

        print("Number of wave numbers " + str(len(wave_num)))
        print("Number of flux numbers = "+ str(len(flux)))
        print subt
    csvfile.close()

1 个答案:

答案 0 :(得分:0)

来自Python文档:

  

map(function,iterable,...)

     

...如果一个迭代比另一个迭代短   假设延长了无项......

我猜你的列表长度不一样,所以它试图从浮点数中减去一个无。