mercredi 15 juin 2016

Python: Checking if passed arguments is empty


So I am trying to pass an argument to the script, ie: main.py -n "provider name"

The code is something like that:

import sys, argparse
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--providername",help="Add a Provider Name")
args = parser.parse_args()
print(type(args.providername))
print(args.providername)

if args.providername is None:
    #do something

I am trying to check a situation where there were no arguments provided for providername and than to do something. For some reason I can't do it just right..

Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire