Can't get around "IndexError: list index out of range"
Terry Reedy
tjreedy at udel.edu
Tue Oct 3 23:05:01 EDT 2006
"Leif K-Brooks" <eurleif at ecritters.biz> wrote in message
news:4522e238$0$25774$4d3efbfe at news.sover.net...
> 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'
Or slice it:
if sys.argv[1:2] != []:
<etc>
tjr
More information about the Python-list
mailing list