0

I have a common utils named utils.py, which is shared across different target (dataset, for example). So, I have to define some target specific attributes, like function and variables.

I have try to do something like this

def setup(name):
    if ...:
        var = val
        import module
    elif ...:
        do something

But from module import * is prohibited within function.

Is there any good practice or any elegant way to do this?

jkjkjk
  • 111
  • 8
  • Related: [Why is “import *” bad?](https://stackoverflow.com/questions/2386714/why-is-import-bad) – Sayse Dec 18 '17 at 07:53
  • 2
    The only good reason to import inside a function is to resolve a circular import. The only good reason to import conditionally is for Python version compatibility. And even then I would prefer `try:` / `except ImportError:`. – Klaus D. Dec 18 '17 at 08:00
  • So you mean it's a design issue? – jkjkjk Dec 18 '17 at 08:05

0 Answers0