Closed MountainX closed 2 years ago
From what I have worked out so far, the solution seems to be:
This is working for me now:
user_regex: {regex1: "^\\d{2}-[a-zA-Z0-9_]+",
regex2: "^\\d{2}-[a-zA-Z0-9А-Яа-яёЁ_]+",
regex3: ...}
However, it is very sensitive and it throws exceptions if everything is not just right.
Is there any alternative for reading a set of user-defined keys from the config file? When yaml is not used, everything is a lot easier and more robust it seems.
I'm guessing the underlying issue is that configargparse works by converting all config file values to command line args before relying on argparse to parse them - and all the special chars are causing problems in argparse rather than in the parse-yaml step. I'm surprised your use-case is working at all, and I'm afraid a true fix would require modifying configargparse to bypass command line args, and have options that are only settable via config file. My initial assumption was that these types of use-cases - where values are complex enough to make it difficult to specify them on the command line - would be better handled by directly reading a config file, without using configargparse (at least for those values).
I'm guessing the underlying issue is that configargparse works by converting all config file values to command line args before relying on argparse to parse them - and all the special chars are causing problems in argparse rather than in the parse-yaml step. I'm surprised your use-case is working at all, and I'm afraid a true fix would require modifying configargparse to bypass command line args, and have options that are only settable via config file. My initial assumption was that these types of use-cases - where values are complex enough to make it difficult to specify them on the command line - would be better handled by directly reading a config file, without using configargparse (at least for those values).
Thanks for sharing your recommendations. I appreciate your work on this package. It's very useful.
I am just switching to configargparse as a replacement for configparser.ConfigParser. Thanks for providing this.
I'm following the instructions at https://pypi.org/project/ConfigArgParse/. In particular, I am attempting this:
I have regex expressions in my config file, similar to:
According to this answer, I guess yaml should handle regex: Python interpreting a Regex from a yaml config file - Stack Overflow
Given the error, which I will paste below, I also tried a few variations such as:
etc.
My code is similar to what is provided in the example at https://pypi.org/project/ConfigArgParse/
Below is the error I am seeing. I tried a few things, such as
Not sure if this issue is related to yaml, my config file formatting or configargparse. With configparser.ConfigParser, I did not need to use yaml. I was using a different approach with ExtendedInterpolation. Since I did not see you mention ExtendedInterpolation, but you did give a yaml example, I followed your lead.