Published on

Avoid file naming conflicts with the standard library

Authors
  • avatar
    Name
    Gene Zhang
    Twitter

Given the file structure:

% tree -L 3
.
├── heapq.py
├── merge_sort.py
└── quick_sort.py    

I ran heapq.py in VSCode, but all the python files were executed. And an error occured:

AttributeError: partially initialized module 'heapq' has no attribute 'heapify' (most likely due to a circular import)

why?

This is because the file was named heapq.py, which conflicted with Python's standard library module heapq.

To avoid any issues, rename the file to something unique like heapq_example.py.