This Is When Keyword Arguments Are Really Useful // Python Tips

preview_player
Показать описание


#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

One can also make this practice more explicit by making arguments keyword-only by planting * argument before them in constructor definition.

vintprox
Автор

Great tip. If the instantiation data is coming as a dict, e.g. from a json file or API, and the dict keys match the instance variable names, it's also very convenient to use dictionary unpacking.

person = Person(**person_dict)

whkoh
Автор

And you don't have to worry about the order unlike with positional args. You could also use arg unpacking to use a dict as kw arguments

leftblank
Автор

Hi Arjan, love your videos!! Could you do one about state pattern?

LuRaKeeN
Автор

One big argument for kwargs is that during refactoring you don't have to track the order of arguments, which saves a bunch of time and kills some bugs in the womb <3

andrzejlipiec
Автор

Can you please make a video on how and when to use super() function?

sharifahmed
Автор

How about using the Builder design pattern in such a case? I come from Java so it's what I'm used to. Idk if it's considered good practice in Python too since kwargs exist but it still seems like something you may want to do. But I'm not sure if an equivalent of the @Builder annotation from Lombok exists.

recarsion
Автор

How might you redesign to have fewer parameters in the first place? A separate address object?

appuser
Автор

Hey, what's your color theme name?

tymoteuszsikora
Автор

Difference between builder pattern vs this approach?

amandhamanda
join shbcf.ru