On Mon, 8 Jan 2001, Paul Prescod wrote: > dir() is one of the "interactive tools" I'd like to work better in the > presence of __exports__. On the other hand, dir() works pretty poorly > for object instances today so maybe we need something new anyhow. I suggest a built-in function "methods()" that works like this: def methods(obj): if type(obj) is InstanceType: return methods(obj.__class__) results = [] if hasattr(obj, '__bases__'): for base in obj.__bases__: results.extend(methods(base)) results.extend( filter(lambda k, o=obj: type(getattr(o, k)) in [MethodType, BuiltinMethodType], dir(obj))) return unique(results) def unique(seq): dict = {} for item in seq: dict[item] = 1 results = dict.keys() results.sort() return results >>> import sys >>> >>> methods(sys.stdin) ['close', 'fileno', 'flush', 'isatty', 'read', 'readinto', 'readline', 'readlines', 'seek', 'tell', 'truncate', 'write', 'writelines'] >>> >>> import SocketServer >>> >>> methods(SocketServer.ForkingTCPServer) ['__init__', 'collect_children', 'fileno', 'finish_request', 'get_request', 'handle_error', 'handle_request', 'process_request', 'serve_forever', 'server_activate', 'server_bind', 'verify_request'] >>> -- ?!ng Happiness comes more from loving than being loved; and often when our affection seems wounded it is is only our vanity bleeding. To love, and to be hurt often, and to love again--this is the brave and happy life. -- J. E. Buchrose
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4