So, it says that create in line 11 is not defined, but it is a recursive function within the class. And In VS Code, it shows me an error at line 6 - it says that I am missing the self argument, but when I add it, it requires 3 arguments in line 23 (why, I can't provide an argument for self, can I ?)
I already tried it with various variations of adding self to the arguments, but nothing worked.
class smarray:
def __init__ (self):
self.array = []
def create(index, dim):
array1 = []
if index < len(dim)-1:
for x in range(0,dim[index]):
array1.append((create(index+1,dim)))
return array1
else:
for x in range(0,dim[index]):
array1.append("nul")
return array1
if index ==0:
self.array = array1
t = smarray()
t = smarray.create(0, [3,4])
error TB:
Traceback (most recent call last):
File "/Users/pc/Documents/VS Code Files/Python testing/testing range.py", line 23, in <module>
t = smarray.create(0, [3,4])
File "/Users/pc/Documents/VS Code Files/Python testing/testing range.py", line 11, in create
array1.append((create(index+1,dim)))
NameError: name 'create' is not defined
self:def create(self, index, dim):It is unclear what you are trying to do with this class: you create an instancet, then you reassign it to the result of a method that returns None... Maybe callt.create(...)instead.selfif missing from parameters in your method. Try this:def create(self, index, dim):...and when you want to call it then use your instance (t) Like this:t.create(0, [3,4])