Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parser.parse_args() meaning
#1
This is a simple question, but I'm asking it anyway, because I can't figure out the answer by myself:
why do we need the args = parser.parse_args() after setting up the arguments in a python program?

So the example would be something like:
from argparse import ArgumentParser
parser = ArgumentParser(description='Get the current weather information for your zipcode')
parser.add_argument('zip', help='zip/postal code to get weather for')
parser.add_argument('--country', '-c', default='us', help='country zip/postal belongs to, default is "us"')

args = parser.parse_args()
args is a random variable, so any one would do. So an object needs to be created, whatever that name is. So how does that work actually? Without creating the object args (if object is correct in this context), the help menu is not going to be displayed.

Thanks!
Reply


Messages In This Thread
parser.parse_args() meaning - by vinci - Oct-14-2020, 09:09 PM
RE: parser.parse_args() meaning - by Gribouillis - Oct-15-2020, 05:54 AM
RE: parser.parse_args() meaning - by vinci - Oct-26-2020, 04:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the meaning of the line of code. jahuja73 0 309 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  Csv writer meaning of quoting mg24 2 1,162 Oct-01-2022, 02:16 PM
Last Post: Gribouillis
  meaning of -> syntax in function definition DrakeSoft 5 1,973 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Operator meaning explanation Sherine 3 2,051 Jul-31-2021, 11:05 AM
Last Post: Sherine
  What is the meaning of k in this function? giladal 3 2,736 Aug-15-2020, 12:32 PM
Last Post: buran
  Here what is the meaning of span=(1,2) ,match='1'? srisrinu 1 2,122 Apr-27-2020, 10:22 AM
Last Post: anbu23
  What is the meaning of mutable data type? qliu 3 2,963 Apr-17-2020, 07:20 PM
Last Post: deanhystad
  Upper-Bound Exclusive Meaning Johnny1998 1 3,366 Aug-02-2019, 08:32 PM
Last Post: ichabod801
  Finding phrases of one semantic meaning VladislavMz 2 30,557 Dec-20-2018, 03:29 AM
Last Post: VladislavMz
  Meaning of some term? hsunteik 2 4,295 Dec-21-2016, 05:47 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020