Do you ever `import` inside a function?

Consider as well libraries that (judiciously) override kernel functions, for example: Image’s Math module.

I’m all for importing inside functions in scenarios like you describe and even importing just above the function where it is first used. Any push back is very much a “this is the way we’ve always done it” scenario (angry monkeys!). It makes no sense to me that you would want to spread these things apart. Same goes for mandating that module attributes must be at the top and that private functions must be at the bottom.

I never considered this and could have come in handy in some code I no longer work in :slight_smile:

1 Like