Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > list/get methods/attributes of a class?

Reply
Thread Tools

list/get methods/attributes of a class?

 
 
bkamrani@gmail.com
Guest
Posts: n/a
 
      02-22-2007
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

 
Reply With Quote
 
 
 
 
Thomas Nelson
Guest
Posts: n/a
 
      02-22-2007
Check out the dir() function. It does what you want, I think.

Tom

On Feb 22, 9:27 am, (E-Mail Removed) 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



 
Reply With Quote
 
 
 
 
Jason
Guest
Posts: n/a
 
      02-22-2007
On Feb 22, 8:27 am, (E-Mail Removed) 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

 
Reply With Quote
 
bkamrani@gmail.com
Guest
Posts: n/a
 
      02-23-2007
On Feb 22, 5:37 pm, "Jason" <(E-Mail Removed)> wrote:
> On Feb 22, 8:27 am, (E-Mail Removed) 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments