Skip to content

Instantly share code, notes, and snippets.

@hitjim
Last active December 28, 2015 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitjim/7533419 to your computer and use it in GitHub Desktop.
Save hitjim/7533419 to your computer and use it in GitHub Desktop.
curiosity regarding behind-the-scenes operations of Python arguments
#! /usr/bin/env python
# hitjim@gmail.com
# usage guide:
# use it
import sys
import argparse
# Argument parsing
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()
# Do you suppose this is really just an assignment of data in memory to a variable
# or is it actually having to parse through and populate a string character-by-character?
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
# This lends me to believe that the cost of arg_str=args.string would be directly proportional
# to the input string's length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment