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
  Error in the method "count" for tuple fff 2 933 Nov-24-2024, 03:29 AM
Last Post: fff
  Multiple variable inputs when only one is called for ChrisDall 2 1,332 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  Couldn't install a go-game called dlgo Nomamesse 14 6,851 Jan-05-2023, 06:38 PM
Last Post: Nomamesse
  how can a function find the name by which it is called? Skaperen 18 6,872 Aug-24-2022, 04:52 PM
Last Post: Skaperen
  function with 'self' input parameter errors out with and without 'self' called dford 12 8,605 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 7,481 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  What is this formatting called? Mark17 2 2,677 Dec-14-2020, 08:42 PM
Last Post: snippsat
  Instance of 'socket' has no 'error' member fedex03 1 4,294 May-13-2020, 03:23 PM
Last Post: deanhystad
  Error: Nested method ? JohnnyCoffee 5 3,998 May-03-2020, 02:43 PM
Last Post: JohnnyCoffee
  Class Instances called in the wrong order IanIous 4 4,216 Mar-06-2020, 02:16 PM
Last Post: IanIous

Forum Jump:

User Panel Messages

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