python2 code get error when using python3.5

This question already has an answer here:

  • Check if a given key already exists in a dictionary 18 answers
  • distutilscross issue when install PyAudio for cross-platform 1 answer
  • how to solve AttributeError: '_Environ' object has no attribute 'has_key' 1 answer

  • has_key is removed in python3, but you shouldn't be using it in 2 either. Use the in operator:

    if self.cross_compile and 'PYTHONXCPREFIX' in os.environ:
    

    has_key() was removed in Python 3.x. Use in or get

    'PYTHONXCPREFIX' in os.environ
    

    Using get

    os.environ.get('PYTHONXCPREFIX') . if does not exists it returns None.

    It can returns False as well, passing it as default value.

    os.environ.get('PYTHONXCPREFIX', False)
    
    链接地址: http://www.djcxy.com/p/28890.html

    上一篇: python:覆盖基于单独字典的单个字典密钥

    下一篇: python2代码在使用python3.5时会出错