Monthly Archive: May 2022

TypeError: Class advice impossible in Python3 0

TypeError: Class advice impossible in Python3

Hits: 0 这里写自定义目录标题 在ubuntu上安装apex时,出现报错信息“TypeError: Class advice impossible in Python3”。原因是使用pip安装时的pip文件可能需要验证,所以正确的安装方式如下: pip3 uninstall apex git clone https://www.github.com/nvidia/apex.git cd apex python3 setup.py install 参考:https://github.com/NVIDIA/apex/issues/116

‘dict’ object has no attribute ‘has_key’ 0

‘dict’ object has no attribute ‘has_key’

Hits: 2这个问题是py2和py3兼容性的问题 在py2中,判断key是否属于dict的写法可以是: d={‘name’:’abc’,’location’:’BeiJing’} if d.has_key(‘location’): print(d[‘location’]) 在py3中,判断key是否属于字典的写法可以是: d={‘name’:’abc’,’location’:’BeiJing’} if ‘location’ in d: print(d[‘location’])