By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,088 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

list/get methods/attributes of a class?

P: n/a
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 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Check out the dir() function. It does what you want, I think.

Tom

On Feb 22, 9:27 am, bkamr...@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

Feb 22 '07 #2

P: n/a
On Feb 22, 8:27 am, bkamr...@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

Feb 22 '07 #3

P: n/a
On Feb 22, 5:37 pm, "Jason" <tenax.racc...@gmail.comwrote:
On Feb 22, 8:27 am, bkamr...@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!

Feb 23 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.