On Mon, 3 Aug 2020 at 08:26, Dominik Vilsmeier <dominik.vilsme...@gmx.de> wrote: > > On 02.08.20 15:36, Sebastian M. Ernst wrote: > > > Hi all, > > > > yet another (possibly bad?) idea from day-to-day work ... > > > > I occasionally need to import a lot of "stuff" from certain modules. The > > "stuff" is usually following a pattern. E.g. I have modules that > > (mostly) collect special exception classes and I usually need them all > > in one push - but nothing else from those modules. > > It seems the responsibility of the package / distribution you are using > to provide appropriate namespaces for their objects. If this "stuff" is > following a certain pattern it seems to be distinct from other parts of > the module, especially since you as a user have the need to only import > those objects. So if they lived in their own namespace then you could > simply do > > from somepkg.errors import *
And of course if they don't do that, you can yourself do: somepkg_errors.py ``` import somepkg __all__ = [x for x in dir(somepkg) if x.endswith('Error')] ``` Your program ``` from somepkg_errors import * ``` Paul _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/JUZBM6F6L4XOBIM2QZNXZLKCKSS75JRJ/ Code of Conduct: http://python.org/psf/codeofconduct/