I am building a small API. For now I am having this workaround solution for optional arguments that need to be send to function later.
if 'A' in request.args:
A = request.args['A']
else:
A = 0
but I feel like that there must be something precise. This seems a bit unprofessional. Something like when I work argparse
parser.add_argument('--A', type=int, required=False')
Please, is it possible to shorten the first section a bit and use some of their functions for it? Thanks
You can use get method something like:
a = request.args.get('A', None)
It puts 'A' value if it exists in args or just None if it doesn't. You can also replace None with any other data like 0 or 'nothing' or everything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With