argc = len(sys.argv)
if (argc < 3 or argc > 5):
printusage()
sys.exit()
insensitive = 1 if ("-i" in sys.argv) else 0
boundaries = 1 if ("-b" in sys.argv) else 0
filename = sys.argv[argc-2]
str = sys.argv[argc-1]
print "Looking for '", str , "' in '" , filename , "'"
The output is
python count_words.py -b -i football.txt goal
Looking for ‘ goal ‘ in ‘ football.txt ‘
Why is there a space before and after ‘goal’ and ‘football.txt’ ? When I try to print the str and filename variable by themselves, they don’t have these spaces.
I’ve also tried using str.strip() in the print, but to no effect.
Any ideas?
The space is not in
sys.argv, it is caused by the use of commas when printing. TryAnd try to avoid shadowing the builtin
str.