Can't get around "IndexError: list index out of range"

Leif K-Brooks eurleif at ecritters.biz
Tue Oct 3 18:21:20 EDT 2006


erikwickstrom at gmail.com wrote:
> I'm trying to get this bit of code to work without triggering the
> IndexError.
> 
> import shutil, os, sys
> 
> if sys.argv[1] != None:
>     ver = sys.argv[1]
> else:
>     ver = '2.14'

Catch it:

try:
     ver = sys.argv[1]
except IndexError:
     ver = '2.14'



More information about the Python-list mailing list