Why does naming a file `json.py` or `requests.py` break things?
IntermediateConceptLanguage essentials & functions
Answer
The script's directory is first on sys.path, so import json finds your json.py instead of the standard library. You see confusing errors like AttributeError: module 'json' has no attribute 'loads' or partially initialized module 'requests' has no attribute 'get' (most likely due to a circular import). Rename the file and delete the stale __pycache__. Check with python -c "import json; print(json.__file__)".
More on Language essentials & functions
Why is Python the default scripting language in so many DevOps teams, and where would you not use it?BeginnerWhat is the difference between mutable and immutable types? Give examples.BeginnerWhat does assignment do in Python, and how do shallow and deep copies differ?BeginnerExplain the mutable default argument bug and how to fix it.IntermediateWhat is the difference between `==` and `is`?BeginnerWhat values are "falsy" in Python, and why does it matter in scripts?Beginner