← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #237141]: how to get total number of instances of one line in sikuli?

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
it seems you have (up to) 5 ModuleType in your file, and you want to get
them all one after another.

- this is the easiest possibility:
- a variable in a function should not have the same name as the function
- a variables and functions should start with a lowercase letter
- a function should have a name, that tells what it does

def getModuleTypesFromFile(file):
    mts = [] # empty list to collect the items
    n = 0
    f = open(file)
    for line in f.readlines():
        if line.count("Module Type/SType")==0 : continue
        (head, mt) = line.split(":")
        mt = mt.strip()
        n = n+1
        print "%d: %s" % (n, mt)
        mts.append(mt) # collect in mt
    f.close()
    return mts # return the collected items in the list

# loop through the list
for mt in getModuleTypesFromFile(file2):
    print "ModulType:", mt # do what is needed with each mt

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