0

What's the best way to define the possible values a parameter/argument may have? Given the config file below, I'm defining the value 'a' for the method argument. Is it possible to define that the other possible options would be 'b' or 'c' without processing it after importing the configs? (i.e. without importing the parameters and checking if 'method' is either 'a', 'b', or 'c' posthoc?

Please note that here I'm not saying the same argument/key can have multiple values.

[defaults]
method = 'a' # possible options are ['a','b','c']
dter
  • 1,065
  • 2
  • 11
  • 22
  • 1
    No - configparser does not do any validation or data-type guessing whatsoever. It is entirely up to the user to provide all the necessary post-processing logic. – ekhumoro Sep 13 '17 at 13:30
  • 1
    What do you mean by "define the possible values "? What do you expect to happen if somebody writes `method = 'z'` in the config file? – Stop harming Monica Sep 13 '17 at 13:36
  • I guess I mixed up defining defaults and validation. Defining the possible arguments in a python dictionary (in a .py script) and post-validating is one solution I could think of. Just wondering if its the best approach to validate an argument? – dter Sep 13 '17 at 13:42
  • @dter. Now you're asking for opinions about what's "best". There are dozens of viable ways to solve this problem, many of which will be either application-specific, or just a matter of taste. – ekhumoro Sep 14 '17 at 11:31

0 Answers0