Interview Prep/Python for DevOps/Language essentials & functions

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__)".

All Python for DevOps questions Roadmap: Python for automation

More on Language essentials & functions