473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to list currently defined classes, methods etc

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

Dec 1 '05 #1
8 1392
Deep wrote:
If i start a python shell. Is there a way to list the currently defined
classes, methods,
variables?


Does this work?
dir()


-Peter

Dec 1 '05 #2
yes that works.
but, it gives one list, which contains everything.
now about inferring types? :)

Dec 1 '05 #3
On Wed, 30 Nov 2005 20:55:46 -0500, Peter Hansen <pe***@engcorp.com> wrote:
Deep wrote:
If i start a python shell. Is there a way to list the currently defined
classes, methods,
variables?


Does this work?
dir() help(__name__)


might be interesting for the OP too ;-)

Regards,
Bengt Richter
Dec 1 '05 #4
Awesome just what i was looking for
now sheepishly i shall RTFM :)

Dec 1 '05 #5
Deep <de**************@gmail.com> wrote:
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
Dec 1 '05 #6
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.

Dec 2 '05 #7
Deep wrote:
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:
def deep(): ... print 'Hello'
... globals()['deep'] <function deep at 0x008ECF70>
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: class deeper: ... def deepest(self):
... print 'goodbye'
... getattr(deeper, 'deepest') <unbound method deeper.deepest> d=deeper()
getattr(d, 'deepest')

<bound method deeper.deepest of <__main__.deeper instance at 0x00A41350>>

Kent
Dec 2 '05 #8
Deep wrote:
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.
help('deep') in the interactive mode gives part of what you seek.


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

Colin W.
Dec 2 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: jblazi | last post by:
Let us assume I have a list like and would like to transoform it into the string '{1,2},{7,8},{12,13}' Which is the simplest way of achiebing this? (The list is in fact much longer and...
5
by: Kenneth | last post by:
<list> seems to be a powerful structure to store the related nodes in memory for fast operations, but the examples I found are all related to primitive type storage. I'm doing a project on C++...
10
by: Andrew McLellan | last post by:
I think I must be missing something about generics, perhaps just about the syntax. I'd like to derive a class MyList from System.Collections.Generic so that it can only contain instance of MyItem....
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
3
by: ImOk | last post by:
In Smalltalk I can get the list of the classes, methods and global variables by querrying a global dictionary. In addition you can get the arguments. I know in PHP one can get the list of...
4
by: Toze | last post by:
I'm using a assembly to load my apllication (ex: Mobi.exe), and now I need to list all forms in my apllication and list all controls (ex: txtname;btnname) inside of each form.
16
by: devicerandom | last post by:
Hi, I am currently using the Cmd module for a mixed cli+gui application. I am starting to refactor my code and it would be highly desirable if many commands could be built as simple plugins. ...
3
by: bkamrani | last post by:
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...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.