[Tutor] Re: ...and another thing
kromag@nsacom.net
kromag@nsacom.net
Fri, 3 Aug 2001 10:24:42 -0700 (PDT)
Once again, the script:
import random
import string
cards=open('\windows\desktop\cards.txt','r')
schmack=cards.readlines()
counter=0
while counter <3:
total_cards=len(schmack)
choose=random.randint(1,string.atoi(`total_cards`))
chosen=schmack[choose]
del schmack[choose]
print chosen
counter=counter+1
Could it be that since I am removing the items in the list by number, that
any time that number is called again I get my index out of range error?:
Traceback (most recent call last):
File "reader.py", line 9, in ?
chosen=schmack[choose]
IndexError: list index out of range
>Exit code: 1
Is there any way to re-assign the numbers (positions?) in the list?
I tried just doing:
schmack=schmack
in hopes that would reassign the positions. Unfortunately I don't have my
books with me today! Yikes!
d