Python Forum
add() takes 2 positional arguments but 3 were given
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
add() takes 2 positional arguments but 3 were given
#1
I have two python files - Addition.py and test,py

Addition.py

class Addition:
    num1 = 0
    num2 = 0

    def add(n1, n2):
        num1 = n1
        num2 = n2
        return num1 + num2
test,py

import Addition

c = Addition.Addition()
print(c.add(2,3))
When I run test.py it throws an error

Error:
add() takes 2 positional arguments but 3 were given
Why am I getting this error and how to solve it?
Reply
#2
The methods gets the 3 arguments c, 2 and 3. The solution is to add the instance in the arguments list def add(self, n1, n2): ...
Reply
#3
Why do you need the class at all?
Reply
#4
(Feb-08-2020, 08:42 AM)ndc85430 Wrote: Why do you need the class at all?

I was getting an error while creating an unofficial API. In order to analyse the error I made this test case. Thank you btw.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Class takes no arguments bily071 2 598 Oct-23-2023, 03:59 PM
Last Post: deanhystad
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,858 Oct-17-2022, 06:29 PM
Last Post: paulo79
  Error: _vhstack_dispatcher() takes 1 positional argument but 9 were given alexfrol86 3 5,715 May-09-2022, 12:49 PM
Last Post: deanhystad
  TypeError: missing 3 required positional arguments: wardancer84 9 10,663 Aug-19-2021, 04:27 PM
Last Post: deanhystad
  Checking the number of arguments a function takes Chirumer 3 2,111 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  TypeError: max_value() missing 2 required positional arguments: 'alpha' and 'beta' Anldra12 2 4,167 May-15-2021, 04:15 PM
Last Post: Anldra12
  Class Takes No Arguments horuscope42 4 4,754 Oct-26-2020, 11:10 PM
Last Post: not_username1234
  How to reuse positional arguments entered in terminal. rcmanu95 1 1,841 Jul-04-2020, 01:00 AM
Last Post: bowlofred
  Class takes no arguments Nazartfya 2 4,503 Jun-27-2020, 12:45 PM
Last Post: Nazartfya
  Why Car() takes no arguments louis216 2 2,544 Jun-25-2020, 03:16 AM
Last Post: louis216

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020