Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
When writing Python-based apps (e.g. Django, Flask, etc.), it's often the case that import statements can be found all over the place, often more than once for the same module. For example, you can...
#1: Initial revision
Does the location of an import statement affect performance in Python?
When writing Python-based apps (e.g. Django, Flask, etc.), it's often the case that `import` statements can be found all over the place, often more than once for the same module. For example, you can: - have the imports at the top of a module; - place the imports inside the functions where they're actually used; - end up importing the same module multiple times (e.g. both modules `a.py` and `b.py` have `import math` in it); So, while you can place your `import` statements anywhere: 1. is there a *noticeable* cost (e.g. memory, performance/speed, etc.) associated with a particular choice? And 2. what's the "best practice" for module `import`s and why?