If i start a python shell. Is there a way to list the currently defined
classes, methods,
variables? 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
yes that works.
but, it gives one list, which contains everything.
now about inferring types? :)
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
Awesome just what i was looking for
now sheepishly i shall RTFM :)
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
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.
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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++...
|
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....
|
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...
|
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...
|
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.
|
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.
...
|
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...
|
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 {
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| | |