相关疑难解决方法(0)

在python中,对日期字段进行排序,字段有时可能为null

我很难想出一个灵巧的方法来处理这种情况.我从数据库读回来的数据.我想对accoutingdate进行评论.但是,accoutingdate有时可能为空.我目前正在做以下事情:

results = sorted(results, key=operator.itemgetter('accountingdate'), reverse=True)
Run Code Online (Sandbox Code Playgroud)

但是,由于一些accoutingdates为null,这种炸弹的"TypeError:无法将datetime.date与NoneType进行比较".

什么是"最正确"或"最恐怖"的方式来处理这个问题?

python sorting

22
推荐指数
2
解决办法
9238
查看次数

标签 统计

python ×1

sorting ×1