473,322 Members | 1,911 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,322 software developers and data experts.

introspection

How do I import a module and then ask it to show me its methods or other
aspects about itself during execution? I'd like to do something such as
this:

import win32api

print win32api.methods()

I'd like to write some test scripts that load modules and probe them for
information about themselves.
Sep 1 '06 #1
4 1357

brad tilley wrote:
How do I import a module and then ask it to show me its methods or other
aspects about itself during execution? I'd like to do something such as
this:

import win32api

print win32api.methods()

I'd like to write some test scripts that load modules and probe them for
information about themselves.
Hi Brad,

You might like to look at the built-in inspect module.

Cheers,
John

Sep 1 '06 #2
brad tilley <rt*****@vt.eduwrites:
How do I import a module and then ask it to show me its methods or other
aspects about itself during execution? I'd like to do something such as
this:

import win32api

print win32api.methods()

I'd like to write some test scripts that load modules and probe them
for information about themselves.
As well as the 'inspect' module, you may be able to get some distance
just with builtin functionality::
>>import re
>>dir(re)
['DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE',
'S', 'U', 'UNICODE', 'VERBOSE', 'X', '__all__', '__builtins__',
'__doc__', '__file__', '__name__', 'compile', 'engine', 'error',
'escape', 'findall', 'finditer', 'match', 'purge', 'search',
'split', 'sub', 'subn', 'template']
>>[(n, getattr(re, n)) for n in dir(re)]
[('DOTALL', 16), ('I', 2), ('IGNORECASE', 2), ('L', 4), ('LOCALE',
4), ('M', 8), ('MULTILINE', 8), ('S', 16), ('U', 32), ('UNICODE',
32), ('VERBOSE', 64), ('X', 64), ('__all__', ['match', 'search',
'sub', 'subn', 'split', 'findall', 'compile', 'purge', 'template',
'escape', 'I', 'L', 'M', 'S', 'X', 'U', 'IGNORECASE', 'LOCALE',
'MULTILINE', 'DOTALL', 'VERBOSE', 'UNICODE', 'error',
'finditer']),
[...]
]
>>[n for n in dir(re) if hasattr(getattr(re, n), '__call__')]
['compile', 'escape', 'findall', 'finditer', 'match', 'purge',
'search', 'split', 'sub', 'subn', 'template']

--
\ "Madness is rare in individuals, but in groups, parties, |
`\ nations and ages it is the rule." -- Friedrich Nietzsche |
_o__) |
Ben Finney

Sep 1 '06 #3
brad tilley wrote:
How do I import a module and then ask it to show me its methods or other
aspects about itself during execution? I'd like to do something such as
this:

import win32api
dir(win32api)
help(win32api)

and also

import inspect
help(inspect)

</F>

Sep 1 '06 #4
Fredrik Lundh wrote:
brad tilley wrote:
>How do I import a module and then ask it to show me its methods or
other aspects about itself during execution? I'd like to do something
such as this:

import win32api

dir(win32api)
help(win32api)

and also

import inspect
help(inspect)

</F>
Great info guys! Thanks.
Sep 1 '06 #5

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

Similar topics

1
by: Rim | last post by:
Hi, Is there a way to get any sort of introspection which would return the content of an instance *in the order they were declared or executed* as opposed to alphabetical order? Example: ...
2
by: Vsevolod (Simon) Ilyushchenko | last post by:
Hi, Last year I have written a Perl module to serve as a backend to Macromedia Flash applications: http://www.simonf.com/amfperl I have just rewritten it in Python, which I have not used...
4
by: Benjamin Rutt | last post by:
I'm trying to learn about introspection in Python. my ultimate goal is to be able to build a module "text database" of all modules that are in the sys.path, by discovering all candidate modules...
0
by: Steven T. Hatton | last post by:
I suspect the core language is not the level at which introspection should be implemented in C++. That has been the choice of C#, and Java. Both of these languages made some trade-offs to...
4
by: Steven T. Hatton | last post by:
Has there been any substantial progress toward supporting introspection/reflection in C++? I don't intend to mean it should be part of the Standard. It would, nonetheless, be nice to have a...
1
by: James Geurts | last post by:
Hi, Can someone tell me how to test if a field is a const? I am using the FxCop introspection engine, but I suppose I could use reflection if required. for example, the following would return...
2
by: greg.corson | last post by:
Hi, I'm in the process of building a complex system using a sort of "system services" model. I'm looking at putting together various services like serialization, networking, 2D/3D rendering,...
8
by: R. Bernstein | last post by:
In doing the extension to the python debugger which I have here: http://sourceforge.net/project/showfiles.php?group_id=61395&package_id=175827 I came across one little thing that it would be nice...
3
by: James Stroud | last post by:
Hello, I wanted to automagically generate an instance of a class from a dictionary--which might be generated from yaml or json. I came up with this: # automagical constructor def...
14
by: Dave Rahardja | last post by:
Is there a way to generate a series of statements based on the data members of a structure at compile time? I have a function that reverses the endianness of any data structure: /// Reverse...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.