0

Why am I getting these errors: Console: "TypeError: printTodos() missing 1 required positional argument: 'self'"

Squiggly underline in VS code under "TodoList" on the last 2 lines with the error "No value for argument 'self' in unbound method callpylint(no-value-for-parameter)"

class TodoList:
    def __init__(self, todos):
        self.todos = todos
        self.count = 1
        self.indent_width = "  "

    def add_todo(self):
        response = input("Please input a todo: \n")
        self.todos.append(self.indent_width + response)

    def printTodos(self):
        for todo in self.todos:
            print(self.indent_width + str(self.count) + "." + todo)
            self.count += 1

todo_list = TodoList(["Have fun", "Chill"])

while (True):
    TodoList.add_todo()
    TodoList.printTodos()

Thanks for any advice!

2 Answers2

1

Change from this

while (True):
    TodoList.add_todo()
    TodoList.printTodos()

To this

while (True):
    todo_list.add_todo()
    todo_list.printTodos()
Ryujinzz
  • 74
  • 3
-3

You need to have indent_width in your init argument

class TodoList:
    def __init__(self, todos, indent_width):
        self.todos = todos
        self.count = 1
        self.indent_width = "  "

    def add_todo(self):
        response = input("Please input a todo: \n")
        self.todos.append(self.indent_width + response)

    def printTodos(self):
        for todo in self.todos:
            print(self.indent_width + str(self.count) + "." + todo)
            self.count += 1

todo_list = TodoList(["Have fun", "Chill"])

while (True):
    TodoList.add_todo()
    TodoList.printTodos()
jameshgrn
  • 16
  • 2