Python Forum
how to make class and instance method (multiple decorator) ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to make class and instance method (multiple decorator) ?
#1
I want make a method like in the following example

class foo():
   
   @classmethod
   @instancemethod # problem:NameError: name 'instancemethod' is not defined
   def method(cls, self):
        print("method class =", cls)
        print("method object =", self)

example = foo()
example.method()
#___output___
# method class = .......
# method object = .....
how can I make it in other way ?

Thanks
Reply


Messages In This Thread
how to make class and instance method (multiple decorator) ? - by harun2525 - May-27-2017, 10:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 231 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  super() and order of running method in class inheritance akbarza 7 722 Feb-04-2024, 09:35 AM
Last Post: Gribouillis
  the order of running code in a decorator function akbarza 2 518 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Can I use logging in a class (without multiple messages) mevan 2 590 Oct-16-2023, 11:08 PM
Last Post: mevan
  Curious about decorator syntax rjdegraff42 14 2,084 May-03-2023, 01:21 PM
Last Post: rjdegraff42
  Using one child class method in another child class garynewport 5 1,571 Jan-11-2023, 06:07 PM
Last Post: garynewport
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,306 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  class, attribute and method Frankduc 9 2,459 Feb-27-2022, 09:07 PM
Last Post: deanhystad
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 1,757 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  Access instance of a class Pavel_47 5 2,083 Nov-19-2021, 10:05 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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