dir(..) vs. PyList_GetItem

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Apr 20 04:22:23 CEST 2000


Mark Pope wrote:
> 
> The code I posted was just a snippet.
> I have already successfully imported the module. I now need to get a list of
> the functions it exposes.

Are you *sure* you have imported the module properly?
Because the result you posted looked an awful lot like
you were looking at an empty module. Note that even if
you imported the module previously, PyModule_New will
*still* create a new module object. 

Can you post the code you actually ran?

If you've got the right module object, I can't imagine
why looking at the keys of the module dict wouldn't
work -- particularly since it works in Python, too:

>>> import string
>>> dir(string)
['__builtins__', '__doc__', '__file__', '__name__', '_idmap', '_idmapL',
'_lower', '_re', '_safe_env', '_swapcase', '_upper', 'atof',
'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize',
'capwords', 'center', 'count', 'digits', 'expandtabs', 'find',
'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters',
'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits',
'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitfields',
'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace',
'zfill']
>>> string.__dict__.keys()
['_safe_env', '_idmap', '_swapcase', 'capitalize', 'atoi_error',
'octdigits', 'rfind', 'index', 'expandtabs', 'center', 'join', 'lower',
'digits', 'atof', '__name__', 'hexdigits', 'atol', 'zfill', 'count',
'atoi', 'atof_error', '_re', 'swapcase', '__file__', '__builtins__',
'joinfields', 'lowercase', '__doc__', 'translate', 'rstrip', 'split',
'splitfields', '_lower', 'atol_error', 'rindex', 'whitespace',
'_idmapL', '_upper', 'rjust', 'find', 'ljust', 'strip', 'index_error',
'capwords', 'replace', 'maketrans', 'uppercase', 'lstrip', 'letters',
'upper']
>>>

The only difference seems to be that dir() sorts the
list.

-- 
Greg Ewing, Computer Science Dept,
+--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+



More information about the Python-list mailing list