IF your indentation is accurate, it is causing you to try to call HeapSort in your definition of HeapSort.
Instead you would want
class HeapSort():
...
def main():
L = [6, 4, 2, 8, 1, 9, 3, 0, 12, 5]
print(L)
h = HeapSort()
h.sort(L)
print(L)
if __name__ == '__main__':
main()
This allows you to run the file in which you define your class, and if other files import the class, it will not run the code.
EDIT
The above will fix the error that you are getting, but if you see @Matt's comments, but you are running tests within your heapsort.py
file, you should move these to an external heapsort-tests.py
file and import your class with
from heapsort import HeapSort
EDIT 2
If you are treating this as a class you want to use and pass around as an instantiated object, then you need to pass self
to all of your methods and call them with self.method_name()
, i.e. self.sink(x,y)
. If not, you would sort by calling something like HeapSort.sort(L)
instead of creating h
.