On Sat, Mar 03, 2018 at 02:33:36PM -0500, Terry Reedy wrote: > def autoload(mod, cls, *args, **kwargs): > from mod import cls > return cls(*args, **kwargs) > > obj = autoload(yourmodule, YourClass)
That won't work unless yourmodule and YourClass have already been imported, since you'll get NameError. You need to pass the names as strings, something like: # also untested def autoload(mod, cls, *args, **kwargs): module = __import__(mod) # or use importlib K = getattr(module, cls) return K(*args, **kwargs) obj = autoload('yourmodule', 'YourClass') -- Steve _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/