What is parsing?
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: https://stackoverflow.com/questions/2933192/what-is-parsing-in-terms-that-a-new-programmer-would-understand Why do I need to "parse" the arguments? Please see this code: https://code.sololearn.com/cOHTRv83X8aM/?ref=app
12/12/2019 3:07:14 PMAlina Sansevich
11 AnswersNew Answer
👍🤣 I'm thinking maybe I don't really need to understand this to use the argparse module, but I would like to anyway, otherwise it becomes a "black box" in my 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)"?
Hope this helps: https://en.m.wikipedia.org/wiki/Parsing
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. 😃💡👍
Alina Sansevich good to hear 👍
Hmm, I see.my bad :). I don't know then maybe it refers to how your command treated inside the cli, maybe it parses the argsparse :))
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.