# Python Click Part 3 of 4

## Метаданные

- **Канал:** AssemblyAI
- **YouTube:** https://www.youtube.com/watch?v=tb_IG0lF27Y
- **Дата:** 09.08.2021
- **Длительность:** 4:16
- **Просмотры:** 327

## Описание

Part three of a four part series on how to use Python Click. Click is a Python library for building command line interfaces. In this part of the series we'll go over how to make a pass decorator, how to use a pass decorator, and how to add optional arguments to a function

Full text tutorial here - https://www.assemblyai.com/blog/the-definitive-guide-to-python-click

## Содержание

### [0:00](https://www.youtube.com/watch?v=tb_IG0lF27Y) Segment 1 (00:00 - 04:00)

okay so part four we're going to make a pass decorator and all we're going to do here is really do pass dict equals click dot make pass decorator and we're going to pass the type dict so that we can pass a dictionary so let's make a command that we're going to pass the dictionary to we're going to call this one get keys yeah get keys oops um and then at click dot pass oh we know i don't think we do add click i think it's just past because we defined it earlier past dict def get keys and we'll pass it the dictionary object subject okay um what are we gonna do here we'll just get the keys dictionary so keys equals dick dot get i think i should just do get dick dot keys and then so here we're gonna go over uh oh actually yeah we're going to oh i did four and five in the same step okay well we're gonna pass some options here for colors to pass in here um so the way we're gonna do that is click the option and we'll give one you know one dash and one dash option so dash c and then dash color uh and then we'll give it a help is equal to pass what color you want your text to be in here um all right so what we're going to do is we're going to make use of click. secco which is click. echo with a style on it and i'll show you both styles so you can see what it looks like and we'll just um we'll just do keys dot json probably i think um color equals uh it's a dict color um color if ooh maybe i'll call it color that might be a better idea color if color else blue i don't know and then we'll see how that goes for us so python walkthrough click the get keys dash dash uh blue yeah oh no dash that's color haha that's color blue yeah there we go okay no example doc docket keys no such option dash color possible oh right very nice actually oh so it actually should be dash c and dash color that's the usual notation what's it called that's the norm uh unexpected keyword argument color did i is this not how you spell the word color this one's kind of okay um and about us there he goes look up those this is about if i was spelling the word color correctly um i actually think i have to make this color and not underscore color i think that might be why it's messed up so um python walkthrough click and download get keys um dash c let's do green oh uh whoa what's going on here is this not right really oh there it is okay i didn't save the file okay that's what i thought happened so yeah now this prints this in green and then if we don't pass anything here prints it in blue cool so that is how you do this part and now we're going to create two functions that will win which one will invoke the other so

---
*Источник: https://ekstraktznaniy.ru/video/13359*