Tabs and space error

Hi,
I am trying to execute the following code, got from this forum:

class TestIndexInArray:
	def __init__(self, arr):
        '''
        @param arr: array to be tested
        '''
		self.arr = arr

	def printItemsIndex(self):
		'''
		Prints the index of each item in a given array
		'''
		# message to tell us when the function was called
		print(f'Print indexes for {self.arr}:')
		for i in self.arr:
			# find the index of i in arr
			itemIndex = self.arr.index(i)
			print(itemIndex)
		print('\n')


	def findItemAtIndex(self, index):
        '''
        @param index: refers to the location of the item in the array
        '''
		print(f'Item at {index} in {self.arr}:')
		try:
			print(self.arr[index])
		except IndexError:
			print(f'> error: index at {index} does not exist')
		print('\n')


if __name__ =="__main__":
    def header(num):
        print(f'Test #{num}\n' + '='*40 + '\n')

    header(1)
    arr_one = TestIndexInArray([4, 9, 12, 3, 5, 24])
    arr_one.printItemsIndex()
    arr_one.findItemAtIndex(0)
    arr_one.findItemAtIndex(2)
    arr_one.findItemAtIndex(5)
    arr_one.findItemAtIndex(6)

    header(2)
    arr_two = TestIndexInArray([])
    arr_two.printItemsIndex()
    arr_two.findItemAtIndex(0)

I am getting following errors:

File “/home/zulfi/PycharmProjects/Classes/exceptionProg.py”, line 3
‘’’
^
TabError: inconsistent use of tabs and spaces in indentation

Process finished with exit code 1

Somebody please guide me.

Zulfi.

You are likely mixing tabs and spaces when indenting your code. Use your code editor to find mixed tabs and spaces.

Hi,
Sorry I don’t know how to do that. This is very much technical.

Somebody please guide me.

Zulfi.

Hi,

I solved this problem by first trying with notepad which did not work but then by clicking the ‘bulb’ which converted the tabs into spaces.
Zulfi.

1 Like