Skip to content

Parse input natively with argparse instead of creating a separate function #4

Open
@bobleesj

Description

@bobleesj

Potential area of improvement

As discussed in #3 (comment), the tup function below is used to parse a string of two integers separated by a comma.

def tup(s):
if not isinstance(s, str):
raise TypeError("Input must be a string of two integers separated by a comma.")
try:
l, h = map(int, s.split(","))
return l, h
except ValueError:
raise ValueError("Input must be two integers separated by a comma (e.g., '1,5')")

tup is used as an input to the parser.add_argument function shown below:

)
parser.add_argument(
"--xrange",
default=None,
type=tup,
nargs="*",
help="the x-range over which to calculate NMF, can be multiple ranges (e.g. --xrange 5,10 12,15)",
)

Suggestion

Recommended by @sbillinge , instead of creating a separate nested function called tup, we shall use argparse to parse the input more gracefully. I am currently not so familiar with the argparse library at the moment. Once we are done with the cookiecutting release process, we can re-visit this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions