python argparse tutorial (beginner - intermediate) anthony explains #044

preview_player
Показать описание
today I explain some of the basics of argument parsing in python with the argparse module!

==========

I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!
Рекомендации по теме
Комментарии
Автор

The best video on argparse that I've ever seen. Really great video. Thanks for sharing.

adwaithrajesh
Автор

Awesome Video again! The subparsers were new to me. Now I know how they work ;-)
I personally like using in the initial parser definition so the default is always displayed in the help when there is one.
Keep up the great work!

theendlessriver
Автор

I was attempting to put together my own way to parse arguments, until I came across argparse. Then I happened upon your video, which was very informative and helpful! Big thumbs up for this!

itsdinguskhan
Автор

David: *talks about how he's working on a python CLI during stream*
Anthony (who writes code, btw): "Have you seen my argparse wideo?"
YouTube: "Hey David, checkout this cool video from Mr. Writes code about argparse
David: "THE AI IS TOO GOOD, HOW DID IT CROSS INTO TWITCH?"

DavidDellsperger
Автор

This made argparse click and make sense

gatorduck
Автор

Great video Anthony, I'll definitely use it as my go-to recommendation for people new to argparse. :)

Regarding the `action='append'` use case: I was writing a port scanner the other day and knowing of it would've helped me a lot. :D This way you can specify multiple ports or multiple target machines.

nilsmuller
Автор

wow, just wow. Thank you and subbed :)

a_maxed_out_handle_of__chars
Автор

Perhaps added to argparse after this video was published but I've recently discovered and it's wonderful. For example if you add an argument "--save-output" you can call --save-output and it will be set to True or you can call "--no-save-output" and it will be set to False. Very useful feature

tommacnamara
Автор

That was the best explanation i ever seen about argparse, thank you sir.

Sir what about how to check them ? I mean check if "status" and "--force" defined and do some code upon that.

ahmedahmedx
Автор

Thanks, Anthony. What are your goto standard libraries while playing with text files or text parsing or generally working with text? (Asking this as an infra eng handling servers) maybe a playlist of videos would definitely be helpful if you kindly do plan your future topics :)

muddasirkhan
Автор

What is the purpose of subparsers? Are they simply grouping arguments?

ingtob
Автор

Is there a way to store multiple names under 1 argument name? For example instead of typing --log multiple times type --log 1.log 2.log etc.

dd-rvxs
Автор

Hi Anthony! Is there a way to create a CLI that accepts arbitrary arguments the same way that a python function can accept kwargs?

jake
Автор

What IDE do you use to write your code and you have your command line open on a separate window and not part of IDE, correct?

DennisZIyanChen
Автор

Code does not work in beginning: TypeError: main() missing 1 required positional argument: 'argv' This happens even after I type python parse.py hello world

vitamind_forme
Автор

The video is very helpful. Thank a ton!
Can you advise on the following: I'm trying to get the string 'price<20' using argparse. Or of it I have to extract 'price' '<' and '20'. I have done it, but is there a way to use choices or custom type to return error of the string does not match required parameters? If user inputs 'value%-4' for example.

tsankailieva
Автор

Hello AWC, this is certainly my goto tutorial for refreshing my knowledge on argparse. I'm working on a piece of code which would need an optional-positional file. But I don't want to use short/long options for it. Any idea how to do that? I want something like python's argparsing thingy... if I do $ python3 ... this invokes the python interpreter but if I do $ python3 t.py it executes the script. How to implement this optional-positional (script) argument?

akshaymestry
Автор

any thoughts about 'click' pkg?

talalkalai
Автор

It's not in standard library but I highly recommend typer over argparse.

skarfie