list/get methods/attributes of a class?

bkamrani at gmail.com bkamrani at gmail.com
Fri Feb 23 04:01:35 EST 2007


On Feb 22, 5:37 pm, "Jason" <tenax.racc... at gmail.com> wrote:
> On Feb 22, 8:27 am, bkamr... at gmail.com wrote:
>
> > Hello,
> > Sorry guys for this newbie questions. But I wonder if there is a
> > standard or build-in method to know the methods of a class?
>
> > I'm not originally a progrommer and I have worked with python/qt in a
> > basic level. Now I work a package which has many predefined classes
> > which I'm going to resue by importing them. I would like to know more
> > about each imported class, what methods exists and so on. Printing the
> > object or type(object) doesn't say so much.
>
> > Any hint or helps is really appreciated!
> > /Ben
>
> Also, try out the built-in help function on the original class.  It'll
> list the class layout, methods, and any associated document strings.
> (It won't list member variables, though.)  To see all elements in an
> instance or class, use the dir() function.
>
> >>> class Dummy(object):
>
> ...     "A sample class that can have any given data."
> ...     def __init__(self, *args):
> ...             self._args = args
> ...     def GetArgCount(self):
> ...             """Show how many arguments were passed at
> instantiation."""
> ...             return len(self._args)
> ...>>> d = Dummy(1, 2, 'three')
> >>> help(d)          # help(Dummy) also works
>
> Help on Dummy in module __main__ object:
>
> class Dummy(__builtin__.object)
>  |  A sample class that can have any given data.
>  |
>  |  Methods defined here:
>  |
>  |  GetArgCount(self)
>  |      Show how many arguments were passed at instantiation.
>  |
>  |  __init__(self, *args)
>  |
>  |
> ----------------------------------------------------------------------
>  |  Data and other attributes defined here:
>  |
>  |  __dict__ = <dictproxy object>
>  |      dictionary for instance variables (if defined)
>  |
>  |  __weakref__ = <attribute '__weakref__' of 'Dummy' objects>
>  |      list of weak references to the object (if defined)
>
>
>
>   --Jason

Thanks and regards!




More information about the Python-list mailing list