I'm new to python actually and I have a func that will add and sort, so I wanted to print the sorted list table but i'm getting an error
Traceback (most recent call last):
File "source_file.py", line 12, in <module>
App.addsort()
self.mytable.append(['Evans', '4', '2:23.717'])
NameError: name 'self' is not defined
This is the code - what am I doing wrong?
class App:
def __init__(self):
self.mytable = [
('Charlie', '3', '2:23.169'),
('Dan', '5', '2:24.316'),
('Bill', '2', '2:23.123'),
('Alan', '1', '2:22.213'),
]
self.sorted = sorted(self.mytable, key=operator.itemgetter(2))
def addsort():
self.mytable.append(['Evans', '4', '2:23.717'])
print(self.sorted)
App.addsort()