Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bobleesj opened this issue Aug 9, 2024 · 0 comments

Comments

@bobleesj
Copy link
Contributor

bobleesj commented Aug 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant