I'm having a strange issue with a string compare that seems to stem from my use of the argparse module to get a value from the command line. Basically the goal is to take in a number the name of a server and from there perform some action...
./this_script.py -p 3 -s serverA
The number related option works quite well, but for some reason the string related option is failing to pass my error checks.
relevant code is as follows:
parser.add_argument("-s", "--server", help="the server on which to act, either serverA or serverB")
and then the error checking (and currently debugging
if args.server:
print "server given"
print args.server
if args.server is "serverA":
print "server is " + args.server
elif args.server is "serverB":
print "server is " + args.server
else:
sys.stderr.write("error, invalid server given\n")
sys.exit()
So when I call the script and pass it the server argument it always goes to the error condition:
~> ./this_script.py -s serverA
server given
serverA
error, invalid server serverA given
I'm fairly confident that this problem comes from the args.server, as if I hard code the server name then it works without issue.
Thanks in advance for any assistance!