Differences between revisions 1 and 7 (spanning 6 versions)
Revision 1 as of 2007-04-10 10:37:52
Size: 417
Editor: fosca
Comment:
Revision 7 as of 2007-08-31 21:51:28
Size: 1461
Editor: PaulBoddie
Comment: Tidy up recent and previous additions.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Describe I come from a java background. Java has an API that list all classes and their methods that come with Java. Is there anything like that in python? here. = Can Python Introspect Like Java? =
Line 3: Line 3:
I don't know ;) but entering the command "I come from a java background. Java has an API that list all classes and their methods that come with Java. Is there anything like that in python?"

At the Python interpreter prompt, invoking the dir function as follows...
Line 7: Line 9:
into the Python interpreter gives a list of defined classes and variables. ...gives a list of defined classes and variables.
Line 9: Line 11:
Using the TAB key on one of the existing objects opens a list of possible completions, i.e. its methods/attributes. In certain interactive shells (or prompts), such as ["IPython"], using the TAB key on one of the existing objects opens a list of possible completions, i.e. its methods/attributes. For other plainer shells, you can call the dir function supplying an object as an argument to see the contents of that object:

>>> dir(some_object)

== Discussion ==

I'm not sure this is what the OP is asking. I think s/he's referring to the API documentation rather than the API itself. Calling help(object) in the interpreter is a good start for help on an object.

In fact, the dir and help built-in functions make use of Python's introspection capabilities. Another interface can be found in the standard library inspect module. -- PaulBoddie

CL's answer: no, Python cannot introspect like Java; it can only do better.

== API Documentation ==

The DocumentationTools page provides details of tools which can produce API documentation for Python applications and libraries, such as that provided for [wiki:WxPython wxPython] (a GUI-building kit for Python): [http://www.wxpython.org/docs/api/ wxPython API documentation].

Can Python Introspect Like Java?

"I come from a java background. Java has an API that list all classes and their methods that come with Java. Is there anything like that in python?"

At the Python interpreter prompt, invoking the dir function as follows...

>>> dir()

...gives a list of defined classes and variables.

In certain interactive shells (or prompts), such as ["IPython"], using the TAB key on one of the existing objects opens a list of possible completions, i.e. its methods/attributes. For other plainer shells, you can call the dir function supplying an object as an argument to see the contents of that object:

>>> dir(some_object)

Discussion

I'm not sure this is what the OP is asking. I think s/he's referring to the API documentation rather than the API itself. Calling help(object) in the interpreter is a good start for help on an object.

In fact, the dir and help built-in functions make use of Python's introspection capabilities. Another interface can be found in the standard library inspect module. -- PaulBoddie

CL's answer: no, Python cannot introspect like Java; it can only do better.

API Documentation

The DocumentationTools page provides details of tools which can produce API documentation for Python applications and libraries, such as that provided for [wiki:WxPython wxPython] (a GUI-building kit for Python): [http://www.wxpython.org/docs/api/ wxPython API documentation].

Asking for Help/Can Python introspect like Java? (last edited 2011-03-26 23:23:03 by PaulBoddie)

Unable to edit the page? See the FrontPage for instructions.