I'm curious about what goes on behind the scenes when using argparse. I've checked here and here, as apparently Namespace presently only exists in the argparse library.
It's possible I'm using the wrong keywords to search SO/Google. It's also possible that I'm asking a senseless or obvious question, but here we go.
When capturing a string of input in Python via argparse as such:
>python palindrome.py 'Taco cat!?'
When running the code below, I would expect that by specifying parser.add_argument('string'... the resulting Namespace acts as a buffer for the single input string.
The next line where I assign the string to "args" must be the first time we actually parse the input, incurring a workload proportionate to the length of the input string. At this point, "args" actually contains a Namespace object, which cannot be parsed via for loop or otherwise (that I know of).
Finally, in order to parse the input using "for" or some other loop, I use the Namespace object to populate a string. I'm curious how many times this process incurs a compute time proportionate to the original string length?
Which of these steps copy by address or copy by value behind the scenes? Looks like the optimistic worse case would be 2x. Once to create the Namespace object, then once again to assign its content to "arg_str"
#! /usr/bin/env python
import sys
import argparse
parser = argparse.ArgumentParser(description='Enter string to see if it\'s a palindrome.')
parser.add_argument('string', help="string to be tested for palindromedness..ishness")
args = parser.parse_args()
arg_str = args.string
# I can parse by using 'for i in arg_str:' but if I try to parse 'for i in args:'
# I get TypeError: "Namespace' object is not iterable
Thanks for looking!!