I am trying to create some argument parameters for my python file. I only want to accept String type as arguments. Below is my code of foo.py -
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
# options to the user
parser.add_argument('--source_table', type = str, required = True)
args = parser.parse_args()
params = vars(args) # convert arguments to dictionary
print(type(params['source_table'])) # prints <class 'str'>
When I give string arguments as -
>python foo.py --source_table=abc
It prints
<class 'str'>
whereas, even if I type
>python foo.py --source_table=123
it prints
<class 'str'>
I would like throw an error saying that only String type is accepted.