maggienj / ActiveData

Provide high speed filtering and aggregation over data
Mozilla Public License 2.0
0 stars 0 forks source link

For journal entry: imports at the bottom of the page #14

Closed maggienj closed 7 years ago

maggienj commented 7 years ago

For journal entry: Just stumbled upon this during debugging...

Why are these imports at the bottom of the page? in mo_dots\__init__.py

Answer: https://stackoverflow.com/questions/13063390/when-does-import-module-at-bottom-of-file

klahnakoski commented 7 years ago

There are few import patterns:

  1. at the top, which is most popular and easiest to understand, but demands all your dependencies are in a hierarchy
  2. Using _late_import() pattern which allows you to define cyclic module dependencies; your program has two distinct phases: a) setting up the module complex (where these cyclic dependencies are resolved), b) running the program. Late import can also be used to delay imports until a module is actually executed, making initial startup a bit faster; in which case a) setup common classes b) run common code c) setup optional classes d) run optional code 3) Import when required: You will see these as in-line imports: We do not care about speed at this point 4) Import at end: A simple case of late_import(): where only the names are required to be in the module; technically a cyclic dependency, but of the simplest form.