Skip to content
  • root@bd5b2ac4ee38:/build# python3 test.py -l 1 -t 0 -o 'dos'
    log argument: 1
    test argument: 0
    options argument: dos
    root@bd5b2ac4ee38:/build# OPTIONS=uno python3 test.py -l 1 -t 0 -o 'dos'
    log argument: 1
    test argument: 0
    options argument: uno
    root@bd5b2ac4ee38:/build# LOG_LEVEL=feo OPTIONS=uno TEST=666 python3 test.py -l 1 -t 0 -o 'dos'
    Traceback (most recent call last):
      File "/build/test.py", line 31, in <module>
        main()
      File "/build/test.py", line 25, in main
        args = parser.parse_args()
      File "/usr/local/lib/python3.9/argparse.py", line 1818, in parse_args
        args, argv = self.parse_known_args(args, namespace)
      File "/usr/local/lib/python3.9/argparse.py", line 1851, in parse_known_args
        namespace, args = self._parse_known_args(args, namespace)
      File "/usr/local/lib/python3.9/argparse.py", line 2060, in _parse_known_args
        start_index = consume_optional(start_index)
      File "/usr/local/lib/python3.9/argparse.py", line 2000, in consume_optional
        take_action(action, args, option_string)
      File "/usr/local/lib/python3.9/argparse.py", line 1928, in take_action
        action(self, namespace, argument_values, option_string)
      File "/build/test.py", line 16, in __call__
        v = self.type(v)
    ValueError: invalid literal for int() with base 10: 'feo'
    root@bd5b2ac4ee38:/build# LOG_LEVEL=666 OPTIONS=uno TEST=666 python3 test.py -l 1 -t 0 -o 'dos'
    log argument: 666
    test argument: 0
    options argument: uno
    root@bd5b2ac4ee38:/build# LOG_LEVEL=666 OPTIONS=cinco TEST=666 python3 test.py -l 1 -t 0 -o 'dos'
    Traceback (most recent call last):
      File "/build/test.py", line 31, in <module>
        main()
      File "/build/test.py", line 25, in main
        args = parser.parse_args()
      File "/usr/local/lib/python3.9/argparse.py", line 1818, in parse_args
        args, argv = self.parse_known_args(args, namespace)
      File "/usr/local/lib/python3.9/argparse.py", line 1851, in parse_known_args
        namespace, args = self._parse_known_args(args, namespace)
      File "/usr/local/lib/python3.9/argparse.py", line 2060, in _parse_known_args
        start_index = consume_optional(start_index)
      File "/usr/local/lib/python3.9/argparse.py", line 2000, in consume_optional
        take_action(action, args, option_string)
      File "/usr/local/lib/python3.9/argparse.py", line 1928, in take_action
        action(self, namespace, argument_values, option_string)
      File "/build/test.py", line 14, in __call__
        raise ArgumentTypeError(f'Invalid value {v}')
    argparse.ArgumentTypeError: Invalid value cinco
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment