In python django how do you print out an object's introspection? The list of all public methods of that object (variable and/or functions)?


Question

In python django how do you print out an object's inrospection? The list of all public methods of that object (variable and/or functions)?

e.g.:

def Factotum(models.Model):
  id_ref = models.IntegerField()

  def calculateSeniorityFactor():
    return (1000 - id_ref) * 1000

I want to be able to run a command line in the Django shell to tell me all of the public methods of a Django model. The output of running on above would be:

>> introspect Factotoum
--> Variable: id_ref
--> Methods: calculateSeniorityFactor
1
17
2/28/2017 2:39:44 PM

Well, things you can introspect are many, not just one.

Good things to start with are:

>>> help(object)
>>> dir(object)
>>> object.__dict__

Also take a look at the inspect module in the standard library.

That should make 99% of all the bases belong to you.

41
11/3/2011 4:53:28 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon