Nick Coghlan wrote: > Terry Reedy wrote: >> if not hasattr(factory, '__call__'): factory = __import__(factory) > > That won't quite work since the string generally isn't referring to a > module, and due to the quirk of __import__ returning the top level > module since that is what the interpreter needs to bind to a name as > part of a normal import statement. > > This would need to look more like: > > if not hasattr(factory, '__call__'): > mod_name, dot, attr = factory.rpartition('.') > if not dot: > raise ValueError("<something meaningful>") > module = imputil.import_module(mod_name) > factory = getattr(module, attr)
s/imputil/importlib/ (Oops...) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com