[issue12915] Add inspect.locate and inspect.resolve

Vinay Sajip report at bugs.python.org
Thu Oct 20 17:10:17 CEST 2011


Vinay Sajip <vinay_sajip at yahoo.co.uk> added the comment:

The version in logging.config appears to be doing the same job, but is shorter:

def _resolve(name):
    """Resolve a dotted name to a global object."""
    name = name.split('.')
    used = name.pop(0)
    found = __import__(used)
    for n in name:
        used = used + '.' + n
        try:
            found = getattr(found, n)
        except AttributeError:
            __import__(used)
            found = getattr(found, n)
    return found

The line "used = used + '.' + n" could of course be improved.

----------
nosy: +vinay.sajip

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12915>
_______________________________________


More information about the Python-bugs-list mailing list