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.

So a general wildcard import is a bad idea in a lot of ways:

```python
from somemodule import *
```

What I usually do instead is something along the following lines:

```python
import somemodule as _somemodule
_globals = globals()

for _attr in dir(_somemodule): # looking for "stuff"
    if not _attr.endswith('Error'): # the filter - this is not "stuff"
        continue
    _globals[_attr] = getattr(_somemodule, _attr) # the "import"

del _globals, _attr, _somemodule # some cleanup
```

The above selects and "imports" everything ending on "Error" into the
global namespace.

What I would love to do instead is something like a "filtered wildcard
import", maybe through regular expressions or shell-like matching:

```python
from somemodule import *Error
```

Best regards,
Sebastian
_______________________________________________
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/JT27NVYZVXLICUMI6XX57QTVCPL2KGDC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to