# Python Click Part 2 of 4

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

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

## Описание

Part two of a four part series on Python Click. Click is a command line interface library for Python. In this part, we'll learn how to create a command in a group, pass context within the group, and pass mandatory arguments

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

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

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

welcome to part two of the python click tutorial so here we're going to add a command to this group and the way you do that is you just do at example that's our group name and we'll do command and we'll call this command type and what that means uh well i'll write the command later and you'll understand so what we're going to do with this oh maybe that's not a good name maybe we'll call it um typer there we go def typer and returns type of context object that's what it's going to do so now if we do python walk through click typer oh no sorry help we'll see that we've added this command um and this is still here so it tells you returns type of context object so we're gonna do is we're gonna make a context and a click argument i'm just gonna make this in the same video so this will be fine um passing context is a context past context basically tells uh click that we're going to be passing a context object around which is created with a command and then exits when that command exits so because click. group is a command with um that is just essentially a group command and click all of the context objects all of the commands inside of the click dot group example will share the same context so they option and that will allow you to pass different things around in the context without having to pass it in as an argument or parameter into the actual function call so here what i'm going to do is i'll do click. pass context and i'm also going to add click. past arguments so we can add an argument in or sorry click the argument and i'm going to call our argument json because i'm going to pass a json file in okay so what we need to do is we need to add this context object and json object uh okay let's do this so what we're going to do here is essentially create a read in a json file and then create an object out of it um okay wait i'm gonna change the json name to doc and then what we're going to do is we're going to load this document basically so stream equals open doc dict equals json. load stream and then we will close our assign our contacts object to dict okay now we're going to do here is we're going to once again at click. past context we're going to pass context but we're not going to pass any arguments here um because we do not need to so what we're going to do is basically just print the type of the context object type ccx. obj and yeah so python walkthrough click uh so i'm gonna do dash help so we can see you know just what's the usage right so um so example options dot command so let's do that so python walkthrough click that's example there's no options to pass here so we'll pass in our document and i'm going to be playing with this json document that i um got from assembly ai it's a from the transcription of a file through assembly ai and it's got category topics sorted so we can play around quite a bit with the json file so it'll be fun um now let's do typer so we can see class dict okay as we expected nice so that's part two and part three and in part four i'm going to go over making a pass decorator for your dictionary

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