Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 115995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:06:28+00:00 2026-05-11T03:06:28+00:00

Given an instance of some class in Python, it would be useful to be

  • 0

Given an instance of some class in Python, it would be useful to be able to determine which line of source code defined each method and property (e.g. to implement 1). For example, given a module ab.py

class A(object):     z = 1     q = 2     def y(self): pass     def x(self): pass  class B(A):     q = 4     def x(self): pass     def w(self): pass 

define a function whither(class_, attribute) returning a tuple containing the filename, class, and line in the source code that defined or subclassed attribute. This means the definition in the class body, not the latest assignment due to overeager dynamism. It’s fine if it returns ‘unknown’ for some attributes.

>>> a = A() >>> b = B() >>> b.spigot = 'brass' >>> whither(a, 'z') ('ab.py', <class 'a.A'>, [line] 2) >>> whither(b,  'q') ('ab.py', <class 'a.B'>, 8) >>> whither(b, 'x') ('ab.py', <class 'a.B'>, 9) >>> whither(b, 'spigot') ('Attribute 'spigot' is a data attribute') 

I want to use this while introspecting Plone, where every object has hundreds of methods and it would be really useful to sort through them organized by class and not just alphabetically.

Of course, in Python you can’t always reasonably know, but it would be nice to get good answers in the common case of mostly-static code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:06:29+00:00Added an answer on May 11, 2026 at 3:06 am

    You are looking for the undocumented function inspect.classify_class_attrs(cls). Pass it a class and it will return a list of tuples ('name', 'kind' e.g. 'method' or 'data', defining class, property). If you need information on absolutely everything in a specific instance you’ll have to do additional work.

    Example:

    >>> import inspect >>> import pprint >>> import calendar >>>  >>> hc = calendar.HTMLCalendar() >>> hc.__class__.pathos = None >>> calendar.Calendar.phobos = None >>> pprint.pprint(inspect.classify_class_attrs(hc.__class__)) [...  ('__doc__',   'data',   <class 'calendar.HTMLCalendar'>,   '\n    This calendar returns complete HTML pages.\n    '),  ...  ('__new__',   'data',   <type 'object'>,   <built-in method __new__ of type object at 0x814fac0>),  ...  ('cssclasses',   'data',   <class 'calendar.HTMLCalendar'>,   ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']),  ('firstweekday',   'property',   <class 'calendar.Calendar'>,   <property object at 0x98b8c34>),  ('formatday',   'method',   <class 'calendar.HTMLCalendar'>,   <function formatday at 0x98b7bc4>),  ...  ('pathos', 'data', <class 'calendar.HTMLCalendar'>, None),  ('phobos', 'data', <class 'calendar.Calendar'>, None),  ...  ] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 226k
  • Answers 226k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Don't think of a test case as testing a method;… May 13, 2026 at 1:10 am
  • Editorial Team
    Editorial Team added an answer i would load the body with a texture .. body… May 13, 2026 at 1:10 am
  • Editorial Team
    Editorial Team added an answer If you need a specific font, see http://msdn.microsoft.com/en-us/library/ms533034(VS.85).aspx - you… May 13, 2026 at 1:10 am

Related Questions

I'm working on a Python library that interfaces with a web service API. Like
I'm trying to build a set of Lua bindings for a collection of C++
For my current project I want to be able to load some classes from
Python's list type has an index() method that takes one parameter and returns the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.