Answer the question
In order to leave comments, you need to log in
How to parse all command line parameter values in python?
Hello.
I am writing a script that is launched by a third-party application with parameters already set in a certain format.
An example script using the argparse library:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import argparse
def create_parser ():
parser = argparse.ArgumentParser()
parser.add_argument('--allow_ips', nargs='*')
return parser
if __name__ == '__main__':
parser = create_parser()
namespace = parser.parse_args()
print (namespace)
python ./script.py --allow_ips=
python ./script.py --allow_ips=192.160.0.10
python ./script.py --allow_ips=192.160.0.10 192.160.0.11 192.160.0.12
error: unrecognized arguments: 192.160.0.11 192.160.0.12
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question