My most common Python mistake

15 May 2007

For some reason I make this specific error all the time:

if len(sys.argv != 2):
    print "Usage: %s <input file>" % sys.argv[0]
    sys.exit(1)

Can you spot it? It gives the runtime error “object of type ‘bool’ has no len()”. I guess I’m too used to languages that require parentheses around the expression in an if statement.

blog comments powered by Disqus