Comparing 3 Ways to Import Multiple Things from the Same Python Module

preview_player
Показать описание
Lately I've been defining each of them on their own line with the full module path.

Hit the subscribe button to receive more videos like this!

REFERENCE LINKS
---------------------------------------------------

COURSES
---------------------------------------------------
Courses I've created that focus on web dev and deployment topics.

THE TOOLS I USE / GEAR
---------------------------------------------------

FOLLOW ME ELSEWHERE
---------------------------------------------------

TIMESTAMPS
---------------------------------------------------
0:00 -- What we're going to cover in this video
0:36 -- There's multiple ways to import more than 1 variable from the same file
1:31 -- Lately I've been putting each import on its own line
1:55 -- This new style reduces merge conflicts
2:57 -- Another common way avoids merge conflicts too but it requires decisions
4:34 -- You'll occasionally be typing a little bit more but it's not bad
4:51 -- The 1 liner approach makes it harder to sort your imports
6:17 -- This new style may or may not involve more lines total (it depends)
7:40 -- Which import style do you prefer?
Рекомендации по теме
Комментарии
Автор

Personally I prefer the 3rd option but I totally get your point. If I see that devs starts to argue about the styling on the merge requests rather than focus on the feature, I'd put black formatter and stop the nonsense. I might give your approach a go and figure out if it's my cup of tea. Awesome content as always!

ruisugarushia
Автор

At my current job, we use one import per line plus isort to sort imports. That creates a single, unambiguous import order, which basically eliminates merge conflicts in imports.

warrenhenning
Автор

i use line 4 import style everything in one line
reason havent really worked with anyone on git such that i get mearge conflict

drac
Автор

I like how many times you say "specifically" in just a minute.

hemanthkotagiri
Автор

I prefer to import the top module (here `import hello`), and use the full name

vlmath