[Python-Dev] yield without future statement?

Skip Montanaro skip@pobox.com (Skip Montanaro)
Mon, 13 Aug 2001 17:08:52 -0500


    Guido> The latest proposal is to let dir() return more rather than less:
    Guido> it will return the instance variable names *plus* all attributes
    Guido> defined by the class *and* its base classes.

While that may seem like a step in the right direction, it will still break
things and not obviate the need for some sort of warning.  Also, one might
argue that for interactive use it might be less helpful than the current
behavior for users to be overwhelmed with dir() output.  I have these two
functions available to me in interactive sessions:

    def dir(o=globals,showall=0):
        if not showall and hasattr(o, "__all__"):
            x = list(o.__all__)
            x.sort()
            return x
        from __builtin__ import dir
        return dir(o)

    def dirall(o, showall=0):
        attrs = dir(o, showall)
        if hasattr(o, "__bases__"):
            for b in o.__bases__:
                attrs.extend(dirall(b, showall))
        if hasattr(o, "__class__") and o != o.__class__:
            attrs.extend(dirall(o.__class__, showall))
        adict = {}
        for a in attrs:
            adict[a] = 1
        attrs = adict.keys()
        attrs.sort()
        return attrs

If I execute "dirall(gtk.GtkRadioButton())" I get a list with 175 entries.
Granted, that's an extreme, but it suggests that in some cases the output of
a recursive dir won't be all that helpful.

What might be useful is to add a recursive flag to dir so that people can
ask for everything.  That way current behaviour would be preserved but users
could get everything if they wanted to.

Skip