Python error: unsupported operand type(s) for -: 'float' and 'NoneType'
Question: My code is supposed to read and subtract two data lists from each other. Why
am I receiving this error, and how can I resolve it?

Here is the full error:

    
    
    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'
    

Here is the code:

    
    
    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()
    


Answer: From the Python docs:

> map(function, iterable, ...)
>
> ...If one iterable is shorter than another it is assumed to be extended with
> None items...

I'd guess that your lists are not the same length so that it's trying to
subtract a None from a float.

