TypeError: '<' not supported between instances of 'NoneType' and 'str'


Solution 1

Remove the offending tuple from your set:

self.seen = {x for x in self.seen if x[0] is not None}

Solution 2

sorted(self.seen) is going to use < by default. You can supply a cmp or key function if you don't want that.


Related videos on Youtube

Matthew Oujiri
Author by

Matthew Oujiri

Updated on June 13, 2020


  • Matthew Oujiri
    Matthew Oujiri over 2 years

    I"m getting this error as I try to make a ttk.Combobox using the values of a set that I select from a .db file.

    for row in self.sql.execute("SELECT {0} FROM Songinfo".format(self.variable1.get())):
    self.Option2 = ttk.Combobox(self, values=sorted(self.seen), textvariable=self.variable2)
    self.Option2.grid(row=3, column=1)

    self.seen, when printed out returns something like:

    {('Heavy Metal',), ('Soundtrack',), ('Pop/Rock',), ('Metal',), 
     ('Alternative',), ('Alternative & Punk',), ('Rock',),
     ('Pop',), ('Classical Crossover',), (None,)}

    this is a set of genres. I'm getting that error and I'm not sure why, it wasn't an issue till recently, any help is appreciated, thanks.

  • Aaron Bentley
    Aaron Bentley over 2 years
    By adding square brackets, you're introducing a failure case for the empty tuple. Although it's conventional to test for None with is/is not, it's legal to test for it with ==, so it's safer to do {x for x in self.seen if x[0] != (None,)}
  • DYZ
    DYZ over 2 years
    @AaronBentley While in general, you are right, in this case, all tuples are non-empty.