Python Forum
How I can recognize that member is classmethod of staticmethod?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How I can recognize that member is classmethod of staticmethod?
#1
I want to get only MY variables of the class and for this I wrote such a function:

import inspect
class MyClass:
...
...
    @classmethod
    def get_object_dict(cls):
        result = {}
        for key, value in cls.__dict__.items():
            if key.startswith('__') or callable(value): continue
            if inspect.ismethod(value): continue
            result[key] = value
            
        return result
...
...
In my dict 'result' I also get classmethod and staticmethod. How I can do my task?

I found this solution:
if type(value) == classmethod or type(value) == staticmethod: continue
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  @staticmethod and @classmethod akbarza 2 496 Jan-01-2024, 03:43 PM
Last Post: deanhystad
  Class member become static Quasar999 1 669 Sep-16-2023, 12:52 PM
Last Post: deanhystad
  python cant recognize PIP siubikYT 2 744 Jul-19-2023, 06:30 PM
Last Post: Lahearle
  Is it possible to make a program recognize how many clicks it has had on the monitor? jao 0 1,150 Feb-25-2022, 06:31 PM
Last Post: jao
  My program won't recognize the filename. braingoblins 1 1,127 Jan-07-2022, 06:18 PM
Last Post: deanhystad
  labels.append(self.classes.index(member.find('name').text)) hobbyist 1 1,911 Dec-15-2021, 01:53 PM
Last Post: deanhystad
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,643 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas
Star NameError – function doesn't recognize imported modules Sir 4 3,480 Dec-01-2020, 06:36 AM
Last Post: Sir
  Instance of 'socket' has no 'error' member fedex03 1 2,886 May-13-2020, 03:23 PM
Last Post: deanhystad
  Player object wont recognize collision with other objects. Jan_97 3 2,708 Dec-22-2019, 04:08 PM
Last Post: joe_momma

Forum Jump:

User Panel Messages

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