TypeError: unorderable types
我正在创建一个简单的GUI应用程序来管理未知单词,同时学习一种新语言。不过,我有一个列表,我正在尝试按字母顺序从A到Z排序:
1 2 3 4 5 6 | def sort_words(self): sorted_words = sorted(self.words) self.listBox.delete(0, END) for item in sorted_words: self.listBox.insert(END, item.wordorphrase) |
问题是我得到了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /usr/bin/python3.5 /home/cali/PycharmProjects/Vocabulary/Vocabulary.py Traceback (most recent call last): File"/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 361, in <module> main() File"/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 355, in main gui = Vocabulary(root) File"/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 28, in __init__ self.load_words() File"/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 153, in load_words self.sort_words() File"/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 156, in sort_words sorted_words = sorted(self.words) TypeError: unorderable types: Word() < Word() Process finished with exit code 1 |
号
注意,它是一个单词对象列表,而不是字符串。
我该如何分类?
试试
它只在您为word定义
埃多克斯1〔3〕