i am importing a class from module in a package and the prgram is working fine but the line in where i call the class it shows the warning that it is not callable
Importing class
Hello, can you pls show me the code of both files , the one which you are calling and from where you are calling it.
Thanks
Happy Coding !!
how should i share it
You can share it here by writing the file name above and then the code below it or you can mail me at [email protected]
class Sorting:
def init(self, array):
self.array = array
def bubble_sort(self):
for nof in range(len(self.array) - 1):
for idx in range(0, len(self.array) - nof - 1):
if self.array[idx + 1] < self.array[idx]:
temp = self.array[idx + 1]
self.array[idx + 1] = self.array[idx]
self.array[idx] = temp
def selection_sort(self):
for nof in range(len(self.array) - 1):
temp_min_idx = nof
for idx in range(nof + 1, len(self.array)):
if self.array[idx] < self.array[temp_min_idx]:
temp_min_idx = idx
temp = self.array[nof]
self.array[nof] = self.array[temp_min_idx]
self.array[temp_min_idx] = temp
def insertion_sort(self):
for nof in range(1, len(self.array)):
temp = nof - 1
while temp >= 0 and self.array[temp] > self.array[temp + 1]:
val = self.array[temp]
self.array[temp] = self.array[temp + 1]
self.array[temp + 1] = val
temp -= 1
def merge_sort_recursively(self):
lo = 0
hi = len(self.array) - 1
def generate(lo, hi):
if lo == hi:
return [self.array[lo]]
mid = lo + (hi - lo) // 2
return merge_tow_sorted_array(generate(lo, mid), generate(mid + 1, hi))
def merge_tow_sorted_array(l1, l2):
idx1 = 0
idx2 = 0
l3 = []
while idx1 < min(len(l1), len(l2)) and idx2 < min(len(l1), len(l2)):
if l1[idx1] <= l2[idx2]:
l3.append(l1[idx1])
idx1 += 1
else:
l3.append(l2[idx2])
idx2 += 1
while idx1 < len(l1):
l3.append(l1[idx1])
idx1 += 1
while idx2 < len(l2):
l3.append(l2[idx2])
idx2 += 1
return l3
return generate(lo, hi)
from Sorting import Sorting
l1 = [2, 5, 1, 3, 9, 0]
my_sort = Sorting(l1)
ans = my_sort.merge_sort_recursively()
print(ans)
Hey, your code is working fine I tried this on sublime text editor and no warning is there. I hope you are using pycharm editor sometimes it also gives useless warnings.
Btw your code is alright and no issue is there.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.