Last active
December 28, 2015 17:08
-
-
Save hitjim/7533419 to your computer and use it in GitHub Desktop.
curiosity regarding behind-the-scenes operations of Python arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# [email protected] | |
# 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