首页 > 解决方案 > Python 3,TypeError '>' ,从 2.7 到 3 的转换

问题描述

这里是 Python 新手,试图将其他人的代码从 python 2.7 更新到 3。我在这个文件上运行了 2to3,它在 2.7 上运行良好,但似乎语法在 3 中发生了变化?这种语法有什么问题导致错误?我怀疑与'>'相关的错误消息与最大请求有关?这是在带有 anaconda 和 python 3.7 的 jupyter notebook 中运行的。

~/jam2py3/simulation.py in get_max_age(model)
     12 def get_max_age(model):
     13   all_compartments = model.select_compartments(lambda c: True)
---> 14   oldest = max(all_compartments, key=lambda c: c.get_attr('age'))
     15   return oldest.get_attr('age')
     16 

TypeError: '>' not supported between instances of 'NoneType' and 'NoneType'

标签: python-3.x

解决方案


推荐阅读