Why is it considered good style to do all imports in a python application at the beginning, even if what is imported is used only once?
I have been programming only shorter pieces of software for a few month now, around a 1-2 thousand lines of code, and it would seem to me to lead to clearer code, if imports that are used only once to be only imported at the place in the code right what is imported is used. Though all the code I saw so far has no abided to that rule.
Otherwise one sees a long list of imports at the beginning, many of which need to be used only much later - and it is unclear when; maybe the relevant pieces of code have already been replaced by better code, but the import is still lurking there, though it is not really used.
(Maybe some fancy IDE allows one to detect such problems, but I think clear code should be clear be itself not be made clear by the help of an IDE.)
The same question also for function definition - if they're not used really often, why declare them at the beginning of the current file and not at the place they are used?