[BangPypers] Finding methods in a python script

Seshadri_N at Dell.com Seshadri_N at Dell.com
Thu Mar 13 10:29:10 CET 2008


In addition to all the nice tips provided earlier... my 0.2cents !

If your module has doc strings then you can use something like: 

~~~~~~~~~~~~~
import os
help(os) 
~~~~~~~~~~~~~

--
seShadri

-----Original Message-----
From: bangpypers-bounces at python.org
[mailto:bangpypers-bounces at python.org] On Behalf Of Pradeep Kishore
Gowda
Sent: Thursday, March 13, 2008 2:41 PM
To: Bangalore Python Users Group - India
Subject: Re: [BangPypers] Finding methods in a python script

Ah! i forgot about the function parameter list.. Will look into it.

+Pradeep

On 3/13/08, Pradeep Kishore Gowda <pradeep at btbytes.com> wrote:
> On 3/13/08, Heshan Suriyaarachchi <heshan.suri at gmail.com> wrote:
>  > Hi
>
> >    I am talking about a scenario like this
>  >
>  > class A:
>  >     def foo(var1,var2):
>  >         return 'Hello'
>  >     def echo():
>  >         return 'testing'
>  >
>  >
>  > class B:
>  >     def bar(car):
>  >          val = car
>  >         return car
>  >
>  > What I need is to find out the classes and the methods of each 
> class with  > their parameters.
>  > i.e. class A
>  >           foo(var,var)
>  >           echo()
>  >
>  > when using dir() it does not show the methods and the method
parameters .
>
>
>
> ## foo2.py
>  class A:
>         pass
>
>  class ABC:
>         pass
>
>  def foo():
>         return 'Hello'
>
>  def bar():
>         return 899
>
>  PI = 22/7
>
>  ## print_methods.py
>  import types
>  import foo2
>
>  # In python everything is available as a dict  all =  foo2.__dict__
>
>  # run through the items and check whether they are classes are 
> functions  for i in all.keys():
>         if type(all[i]) == types.ClassType:
>                 print i, 'is a class'
>         elif type(all[i]) == types.FunctionType:
>                 print i, 'is a function'
>
>  # of course this gives only the top level functions and classes.
>
>  # Traverse the Tree to get the classes and methods like you wanted.
>
>  # Pradeep
>
>
>  --
>
> Home - http://btbytes.com
>  Heart  - http://sampada.net
>  Yummy! - http://konkanirecipes.com
>


--
Home - http://btbytes.com
Heart  - http://sampada.net
Yummy! - http://konkanirecipes.com
_______________________________________________
BangPypers mailing list
BangPypers at python.org
http://mail.python.org/mailman/listinfo/bangpypers


More information about the BangPypers mailing list