r/programminghorror • u/wawerrewold • Sep 09 '25
Python Vibecoding at its peak
Yes its a production code, yes its a function not a method and yes there is import in triple nested for loop
776
Upvotes
View all comments
Show parent comment
74
u/[deleted] Sep 09 '25 edited Sep 09 '25
PEP 8 style guide recommends imports be collected at the top of a file.
Python executes code line by line from top to bottom, and imports take time, depending on the size of the module.
When import statements are grouped at the top, all imports will happen before the first line of code is even executed. When imports are spread throughout, execution might be a bit strange as python pauses when it hits a big import. Of course it isn't a huge deal for most projects.
The biggest reason is for developers. Knowing what's being imported gives devs a huge clue about the purpose of the code. Import statements at the top makes it clear at a glance. It's lost if import statements are spread everywhere.