How to list currently defined classes, methods etc

D

Deep

If i start a python shell. Is there a way to list the currently defined
classes, methods,
variables?
 
D

Deep

yes that works.
but, it gives one list, which contains everything.
now about inferring types? :)
 
A

Alex Martelli

Deep said:
yes that works.
but, it gives one list, which contains everything.
now about inferring types? :)

You may want to look at module inspect in the standard library.


Alex
 
D

Deep

I have been looking a bit and am stuck at this point.

Given a string, how do i find what is the string bound to.
Let me give an example.

def deep():
print "Hello"

now inspect.ismethod(deep) returns true. (As it should).
But if I am trying to make a list of all bound methods), i use
dir(), which is a list of strings. I get the string "deep" from this
list.
How do I obtain the reference to the method it is bound to.
The same problem can be extended to attributes and classes.
 
C

Colin J. Williams

Deep said:
I have been looking a bit and am stuck at this point.

Given a string, how do i find what is the string bound to.
Let me give an example.

def deep():
print "Hello"

now inspect.ismethod(deep) returns true. (As it should).
But if I am trying to make a list of all bound methods), i use
dir(), which is a list of strings. I get the string "deep" from this
list.
How do I obtain the reference to the method it is bound to.
The same problem can be extended to attributes and classes.

A prettier way is to use epydoc:
http://www.answers.com/main/ntquery?s=epydoc&gwp=13

Colin W.
 
K

Kent Johnson

Deep said:
I have been looking a bit and am stuck at this point.

Given a string, how do i find what is the string bound to.
Let me give an example.

def deep():
print "Hello"

now inspect.ismethod(deep) returns true. (As it should).
But if I am trying to make a list of all bound methods), i use
dir(), which is a list of strings. I get the string "deep" from this
list.

Look it up in the globals() dict: ... print 'Hello'
...
How do I obtain the reference to the method it is bound to.
The same problem can be extended to attributes and classes.

Use getattr() to inspect classes and instances: ... def deepest(self):
... print 'goodbye'
...<bound method deeper.deepest of <__main__.deeper instance at 0x00A41350>>

Kent
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top