python - 'method' object is not subscriptable. Don't know what's wrong -
i'm writing code create unsorted list whenever try insert list using insert method 'method' object not subscriptable error. not sure how fix it. thanks.
class unsortedlist: def __init__(self): self.thelist = list() def __getitem__(self, i): print(self.thelist[i]) def insert(self, lst): x in lst: try: self.thelist.append(float(x)) except: print("oops") mylist = unsortedlist() mylist.insert[1, 2, 3]
you need use parentheses: mylist.insert([1, 2, 3])
. when leave out parentheses, python thinks trying access mylist.insert
@ position 1, 2, 3
, because that's brackets used when right next variable.
Comments
Post a Comment