Skip to main content

argparse custom types

Project description

argparse-custom-types

Special custom types for argparse

How to install

pip install argparse_custom_types

Description

Additional custom types to be used with argparse

How to use

Import argparse_custom_types setup the custom type then pass the function to the type keyword in argparse.add_argument()

Types

  • int_range

    • custom int in range from start to stop (not including) optional step
    def int_range(start: int, stop: int, step: int = 1):
    
    • example:
    t = int_range(5, 21, 5)
    

    int types 5, 10, 15, 20 would be accepted

  • int_above

    def int_above(minimum: int):
    
    • int equal to or above the minimum entered
    • example:
    t = int_above(40)
    

    int types 40 and above would be accepted

  • int_below

    def int_below(maximum: int):
    
    • int equal to or below maximum
    • example:
    t = int_below(25)
    

    int types 25 or below would be accepted

  • int_even

    def int_even(pos_number: bool = True, neg_number: bool = False,include_zero: bool = False):
    
    • even int with option to include negative, zero or exclude positive
    • example:
    t = int_even(neg_number=True)
    

    int types 2, -30, 102 would be accepted int types 1, -29, 101 would not be accepted

  • int_odd

    def int_odd(pos_number: bool = True, neg_number: bool = False,include_zero: bool = False):
    
    • odd int with option to include negative, zero or exclude positive
    • example:
    t = int_odd(neg_number=True)
    

    int types 1, -29, 101 would be accepted int types 2, -30, 102 would not be accepted

  • in_sequence_strings

    def in_sequence_strings(sequence: Union[Tuple[str], List[str]],
                            show_on_invalid: bool = False,
                            case_sensitive: bool = True):
    
    • Value that is in the tuple or list and returns that value as a string.
    • example:
    t = in_sequence_strings(["one", "test", "parser"])
    

    any value not in the list ["one", "test", "parser"] will not be accepted

  • in_sequence_ints

  • def in_sequence_ints(sequence: Union[List[int], Tuple[int]],
                         show_on_invalid: bool = False):
    
    • Int value in sequence will be accepted and return a int value

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argparse_custom_types-0.2.0.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

argparse_custom_types-0.2.0-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page