I'm learning about argparse and can't find a good explanation of what parsing means/does/why is it necessary. Stackoverflow can't reach a good definition either:
Why do I need to "parse" the arguments?
Please see this code:
Thank you Sahand Jalali for your answer.
I'm not mixing the 2 words, I'm asking what's the computer doing when it runs parse_argument
Maybe I should edit my question to: What does parse mean/do in the context of argparse module?
When you pass 355 to scripy.py, why do you say "parse" and not "assign (a value to a parameter)"?
I think you're using argsparse and parsing intercheangeably which are truly different , parsing (in your stackoverflow link ) means you have string and you want to do something with it (parsing). for example :
"Hey I'm Panda" to :
[Hey, i'm , panda] (thats parsing)
But argsparse is an argument you pass to the program as variable. for example in terminal you pass:
Python3 scripy.py 355
355 created using argsparse and passed to the program as a variable(it can be input of a funtion).also it can be use to set flag(e.g. -help, and etc)for a program you're writing .
I hope it would help
Thank you Sonic for your answer, it did help 👍
This part specially:
"A parser is a software component that takes input data (frequently text) and builds a data structure – often some kind of parse tree, abstract syntax tree or other hierarchical structure, giving a structural representation of the input while checking for correct syntax."
When parse_args is called on the parser object, it does much more than an assignment, it builds a structure with all the arguments that it has been given. 😃💡👍
It's a recogniton some patterns in a text. For example, when you read a book, you see words and sentences - your brain parse a text automatically because you learned your native language for many years. But if you try to read a text in a foreign language, you'll see only a sequence of characters, because your brain can't parse this language yet.