← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #216288]: how to loop the creation of a file containing a list, from wich an element is extracted, and a new file containing the reduced list, is created.

 

Question #216288 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/216288

    Status: Open => Answered

RaiMan proposed the following answer:
x = 1 #<-----------x containing the number.
for x in alist:

yes, in the first line you are assigning a number to x, but in the next
line you reassign x to a value from alist, which contains strings.

So my guessing was right ;-)

... and you have more glitches  in your code:

you use alist as an iterator in the outer for loop, but assign a new
value to alist inside the loop: this is not allowed by Python and leads
to unexpected results or even crashes.

alist= list(line):
does nothing else than produce the following: [ "content of line \n" ] which is a list with one entry


        c = random.choice(alist) #choose an element from the list
        print c
        alist.remove(c) #remove it
since alist only has one entry, this is chosen and then you have alist as [ ] which is a list with no entries

and in the end nothing is written to outp.

So pls. try again to tell about your expected results to get better
help.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.