+ 4

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

12th Dec 2019, 3:07 PM
Alina Sansevich
Alina Sansevich - avatar
11 Answers
+ 5
đŸ‘đŸ€Ł 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... đŸ€·â€â™€ïž
12th Dec 2019, 10:53 PM
Alina Sansevich
Alina Sansevich - avatar
+ 4
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)"?
12th Dec 2019, 10:44 PM
Alina Sansevich
Alina Sansevich - avatar
13th Dec 2019, 3:16 AM
Sonic
Sonic - avatar
+ 3
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
12th Dec 2019, 10:38 PM
Sahand Jalali
Sahand Jalali - avatar
+ 3
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. 😃💡👍
13th Dec 2019, 3:41 AM
Alina Sansevich
Alina Sansevich - avatar
+ 3
Alina Sansevich good to hear 👍
13th Dec 2019, 3:44 AM
Sonic
Sonic - avatar
+ 2
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 :))
12th Dec 2019, 10:51 PM
Sahand Jalali
Sahand Jalali - avatar
+ 2
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.
14th Dec 2019, 9:53 AM
Evgeny Malikov
Evgeny Malikov - avatar
+ 1
Ccugd
13th Dec 2019, 3:43 PM
Ibrahime maiga
Ibrahime maiga - avatar
0
Hello friends
13th Dec 2019, 7:10 AM
Surinder Kumar
Surinder Kumar - avatar
0
ŰłÙ„Ű§Ù…
14th Dec 2019, 10:48 AM
Hammad Saidi
Hammad Saidi - avatar