?Method to list out map object's keys on KeyError

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Norman Shelley

    ?Method to list out map object's keys on KeyError

    Is there a way to get at the object one is trying to access with a key to list
    out all the possible keys?
    See the except clause below.

    #!/usr/bin/env python2.2
    from inspect import *
    import sys

    program = """
    abc = {}
    print "abc:", abc
    print abc['def']
    """


    gdct = globals()
    ldct = {}
    try:
    exec program in gdct, ldct
    except KeyError:
    # Some way to get at the abc object to list out all its keys
    # e.g. abc.keys() Of course program could have any map name
    # that would fail and I would like that object's keys
    raise



Working...