Re:Altering Python attribute handling for modules
by dist-epoch on Monday September 11, 2023 @09:44AM
(#37467160)
Python imports don't work like in Java.
import keras.applications.vgg16.VGG16
import keras.applications.vgg16.preprocess_input
preprocess_input(...) # ERROR
keras.applications.vgg16.preprocess_input(...) # CORRECT
Re:Altering Python attribute handling for modules
by Timon3 on Monday September 11, 2023 @01:17PM
(#37470387)
import VGG16, preprocess_input from keras.applications.vgg16
This approach has a couple of downsides:- no editor autocomplete while typing (JS modules have the same downside)
- more difficult to read multiple imports from modules in the same hierarchy (since the "from" parts aren't aligned)
- import sorting becomes less clear (do you sort by imported things or by the module you import from?)
JS uses your suggested format, and I dislike it much more than the Python equivalent due to the reasons stated above.
If still necessary to differentiate, the perfect alternative would be to flip it.
In fact I've always find it strange that an import needs different syntax depending on how you use it. If all imports started with "import" it would be much more consistent and easy to read.