in defense of putting your python imports in the middle of your file (in global scope, not inside functions)
i have never in my life wanted to know the list of all the things a file imports before seeing any of the actual code in the file. if i see something i dont recognize, i would appreciate it more if the import were right above the usage; otherwise, i have to ctrl+f for it anyways. what’s
it’s more annoying to have to add it to the top of the file. auto import things in ides are often broken.
there’s absolutely nothing wrong with importing something multiple times. it costs absolutely nothing; it’s just a no-op the second time. even in C you can do #pragma once to get python-like behavior
the only reason not to do this is that if you put an import in the middle of a function it’s weird (if you import both blobally and locally, then using the thing locally but before the local import errors). so just don’t put the import inside a function
in defense of putting your python imports in the middle of your file (in global scope, not inside functions)
i have never in my life wanted to know the list of all the things a file imports before seeing any of the actual code in the file. if i see something i dont recognize, i would appreciate it more if the import were right above the usage; otherwise, i have to ctrl+f for it anyways. what’s
it’s more annoying to have to add it to the top of the file. auto import things in ides are often broken.
there’s absolutely nothing wrong with importing something multiple times. it costs absolutely nothing; it’s just a no-op the second time. even in C you can do
#pragma once
to get python-like behaviorthe only reason not to do this is that if you put an import in the middle of a function it’s weird (if you import both blobally and locally, then using the thing locally but before the local import errors). so just don’t put the import inside a function
tone: playful
weak. if you’re going to import not at the top of a file put it at the top of the function like a real startup-speed-microoptimizing programmer