list/get methods/attributes of a class?

Discussion in 'Python' started by bkamrani@gmail.com, Feb 22, 2007.

  1. Guest

    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
     
    , Feb 22, 2007
    #1
    1. Advertising

  2. Check out the dir() function. It does what you want, I think.

    Tom

    On Feb 22, 9:27 am, 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
     
    Thomas Nelson, Feb 22, 2007
    #2
    1. Advertising

  3. Jason Guest

    On Feb 22, 8:27 am, 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
     
    Jason, Feb 22, 2007
    #3
  4. Guest

    On Feb 22, 5:37 pm, "Jason" <> wrote:
    > On Feb 22, 8:27 am, 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!
     
    , Feb 23, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oltmans
    Replies:
    6
    Views:
    353
    Terry Reedy
    Mar 11, 2009
  2. DG
    Replies:
    3
    Views:
    337
    Terry Reedy
    Jul 22, 2009
  3. mk
    Replies:
    0
    Views:
    240
  4. mk
    Replies:
    10
    Views:
    360
    Bruno Desthuilliers
    Feb 18, 2010
  5. Kenneth McDonald
    Replies:
    5
    Views:
    326
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page