Python Forum
Getting error when called through instance method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting error when called through instance method
#1
Hello Python Experts

Below code works without any issues when i called it though class method BUT when i called it through instance method , it is not working , may i please know why?

Working Code

class Pizza:
    def __init__(self, size):
        self.size = size
    def get_size(self):
        return "Size={}".format(self.size)

print(Pizza.get_size(Pizza(4555))
Output:
==> Size=4555
Error Code
class Pizza:
    def __init__(self, size):
        self.size = size
    def get_size(self, data):
        return "Size={}".format(self.size)

print(Pizza.get_size(4555))
Error:
aankrose@PS1:~/code$ python3 phase2.py Traceback (most recent call last): File "phase2.py", line 7, in <module> print(Pizza.get_size(4555)) TypeError: get_size() missing 1 required positional argument: 'data'
Reply


Messages In This Thread
Getting error when called through instance method - by aankrose - Mar-02-2019, 05:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple variable inputs when only one is called for ChrisDall 2 505 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  Couldn't install a go-game called dlgo Nomamesse 14 3,185 Jan-05-2023, 06:38 PM
Last Post: Nomamesse
  how can a function find the name by which it is called? Skaperen 18 3,539 Aug-24-2022, 04:52 PM
Last Post: Skaperen
  function with 'self' input parameter errors out with and without 'self' called dford 12 3,174 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,164 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  What is this formatting called? Mark17 2 1,789 Dec-14-2020, 08:42 PM
Last Post: snippsat
  Instance of 'socket' has no 'error' member fedex03 1 2,910 May-13-2020, 03:23 PM
Last Post: deanhystad
  Error: Nested method ? JohnnyCoffee 5 2,862 May-03-2020, 02:43 PM
Last Post: JohnnyCoffee
  Class Instances called in the wrong order IanIous 4 2,870 Mar-06-2020, 02:16 PM
Last Post: IanIous
  How do you add the results together each time a function is called? Exsul 10 5,199 Aug-09-2019, 09:18 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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