[Python-Dev] Add __exports__ to modules
Ka-Ping Yee
ping@lfw.org
Mon, 8 Jan 2001 18:00:08 -0800 (PST)
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