Example wanted for inspect module

Siggy Brentrup bsb at winnegan.de
Tue Aug 21 15:46:30 EDT 2001


"RT" <richard at NOstarfighterSPAM.freeuk.com> writes:

> The inspect module's getmembers() function takes 2 arguments - the object
> whose members you want to retrieve and an (optional) predicate.
> 
> Could somebody please provide an example of how the predicate is used (for
> example - to get only the functions from a module).

Python 2.2a1+ (#2, Aug 20 2001, 08:22:00) 
[GCC 3.0.1 20010811 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket, inspect
>>> inspect.getmembers(socket,inspect.isfunction)
[('getfqdn', <function getfqdn at 0x8116fd4>)]
>>># Ups, but there is:
>>> socket.gethostname
<built-in function gethostname>
>>># Ah, it's not really a module function
>>> inspect.getmembers(socket,inspect.isclass)
[('SSLType', <type 'SSL'>), ('SocketType', <type 'socket'>),
('_closedsocket', <class socket._closedsocket at 0x814ec9c>),
('_fileobject', <class socket._fileobject at 0x8117064>),
('_socketobject', <class socket._socketobject at 0x8116f84>),
('error', <class socket.error at 0x8142aec>), ('gaierror', <class
socket.gaierror at 0x8142d74>), ('herror', <class socket.herror at
0x8142c1c>), ('sslerror', <class socket.sslerror at 0x8149d2c>)]

HTH
  Siggy

-- 
Siggy Brentrup - bsb at winnegan.de - http://oss.winnegan.de/
****** ceterum censeo javascriptum esse restrictam *******




More information about the Python-list mailing list