I found that argparse adds an extra space before an argument. Based on the example code below
def parse_arguments():
parser = argparse.ArgumentParser(
prog='sample',
description='bla bla',
parser.add_argument('-s', '--search', dest='pattern', required=True,
help='search path pattern (e.g. /dir1/dir2/*.ext)')
args = parser.parse_args()
if args.pattern[0] == ' ':
print "One space is added to the argument"
return args
and testing in interactive shell as:
import sys
sys.argv = ['', '-s /Users/user/Desktop/test']
execfile('test.py')
Providing the argument as sys.argv = ['', '-s=/Users/user/Desktop/test']
does not cause such an addition (inspiring from https://stackoverflow.com/a/36376287/2101864).
Is it a documented behavior or do I miss something? Because it is typical that a regular user provide argument adding a space between argument tag and value.