解决 AttributeError: 'dict' object has no attribute 'has_key' 错误的方法

错误原因:

Python 3 已弃用 has_key 这一方法。

错误代码:

1 if all_attendances.has_key(_start):          
2         _attendance = all_attendances[_start]
3         stats.add_attendance(_attendance.clock_in, _attendance.clock_out, 1)

修改后的代码:

1    if _start in all_attendances:   
2        _attendance = all_attendances[_start]
3        stats.add_attendance(_attendance.clock_in, _attendance.clock_out, 1)

 

posted on 2018-09-06 15:53  mentiantian  阅读(4074)  评论(0编辑  收藏  举报