← 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: Answered => Open

Pablo Frank is still having a problem:
you wrote:

>>>so make sure, that x contains the number, when this line is
processed.


x does contain a number: x=1 before the for loop begins:


alist = ('1','2','3','4','5') #"1" already exists, the others should be created one by one when the for loop runs.

x = 1   #<-----------x containing the number.
for x in alist:
    inp = open("C:\\python_texts\\"+str(x)+".txt","r") #open an existing file "x.txt"

    outp = open("C:\\python_texts\\"+str(x + 1)+".txt","w") #write the result (of the below 'for') in
                                                  #a new file.

    for line in inp:
        alist= list(line) #from a list in the file
        print alist
        c = random.choice(alist) #choose an element from the list
        print c
        alist.remove(c) #remove it
        print alist
        for a in alist:
            outp.write(a) #write the new list in "x+1.txt" file
        x = x + 1

outp.close() #close the file to be read:("C:\\python_texts\\"+str(x)+"txt","r")
inp.close() #close the file to be written :("C:\\python_texts\\"str(x + 1)+".txt","w")

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