Python Forum
i need a module for more involved command line parsing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need a module for more involved command line parsing
#21
import argparse

parser = argparse.ArgumentParser(description='desription')
parser.add_argument('arguments', nargs='+', help='some description about the arguments')

args = parser.perse_args()

# your code
The plus sign in nargs will produce an error if there is no argument. It requires at least one. It will take all positional arguments and it will put them to a list args.arguments.

It depends on you to check if there is one argument or more. And if the numbers are positive or both integers or floats. The arguments are strings.
You can use add_argument type option (type=int) but I don't know how to check for two types according to how many arguments are provided. The date parsing is on you too. However, you can write a function do check all of this: the number of the arguments and if they are two the type and if they are positive.
Quote:type= can take any callable that takes a single string argument and returns the converted value

So you can write your own validator function and use it as type argument.

gmpy2 module can do math with arbitrary precision. And it's doing it fast.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#22
python's ints are slower than pike's ints. pike uses libgmp. maybe gmpy2 does, too. that would be useful. it want to do my extreme depth mandelbot graphics with ints to see how far that can get me. maybe i won't have to switch back to pike or c.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  module either imported by a command or itself run as a command Skaperen 2 551 Dec-04-2023, 03:15 AM
Last Post: Skaperen
  review of command line parsers Skaperen 2 2,032 Mar-11-2021, 07:39 PM
Last Post: Skaperen
  command line options Skaperen 5 2,597 Aug-14-2020, 08:48 AM
Last Post: DeaD_EyE
  opening python from the command line takes a long time to load? abdulkaderanwar 4 2,901 Jun-22-2020, 03:42 AM
Last Post: abdulkaderanwar
  f-string in command line arguments Skaperen 0 1,546 May-05-2020, 11:49 PM
Last Post: Skaperen
  my own command line option parser Skaperen 0 1,641 Mar-27-2020, 04:14 AM
Last Post: Skaperen
  want suggested module for e-mail parsing Skaperen 0 1,483 Jul-26-2019, 08:52 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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