Python Forum
Difference between method and attribute holding a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference between method and attribute holding a function
#3
(Jun-29-2024, 07:57 PM)ulrich Wrote: print('Dict: ', mc.__dict__) # shows functionAttribute but not method
Methods defined in the class body are part of the class attribute dictionary,not the instance dictionary.
# Instance dictionary
>>> mc.__dict__
{'functionAttribute': <function function at 0x000001B9B775EAC0>

# Class attribute dictionary,now see the <method>
>>> MyClass.__dict__
mappingproxy({'__dict__': <attribute '__dict__' of 'MyClass' objects>,
              '__doc__': None,
              '__init__': <function MyClass.__init__ at 0x000002413180EB60>,
              '__module__': '__main__',
              '__weakref__': <attribute '__weakref__' of 'MyClass' objects>,
              'method': <function MyClass.method at 0x000002413180EC00>})
Reply


Messages In This Thread
RE: Difference between method and attribute holding a function - by snippsat - Jun-30-2024, 08:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,388 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,816 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  i want to use type= as a function/method keyword argument Skaperen 9 2,212 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  AttributeError: 'function' object has no attribute 'metadata 3lnyn0 5 5,038 Mar-28-2022, 04:42 PM
Last Post: Larz60+
  class, attribute and method Frankduc 9 2,777 Feb-27-2022, 09:07 PM
Last Post: deanhystad
Photo Raspberry PI writing to RS485 driver, DIR pin not holding state zazas321 2 2,269 Oct-30-2020, 06:23 AM
Last Post: zazas321
  Building a method name in a function ffgth 9 3,588 Oct-19-2020, 01:21 PM
Last Post: buran
  function/method help myv5285 3 2,998 May-17-2020, 04:19 AM
Last Post: buran
  Accessing method as function object ClassicalSoul 2 2,148 Feb-14-2020, 09:31 PM
Last Post: wavic
  function vs method prateekshaw 2 2,326 Nov-14-2019, 07:00 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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