← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #189827]: Reading and writing file query

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Sorry, my fault, I left out a needed bracket, that you then added at the
wrong place :-(

fout.write( "%s\n%s\n%s\n" % (arr[0], arr[1], "Login is successful") )

The above in steps for you to understand:

formatString = "%s\n%s\n%s\n" # template with placeholders %s
formatParameters = (arr[0], arr[1], "Login is successful") # corresponding list of fill ins
formatOutput = format String % formatParameters # the formatting operator %
fout.write( formatOutput) # write out the formatted string

*** Excel support
Sikuli does not have direct support for reading/writing Excel sheets.

With enough Python knowledge you might use the packages xlrd and xlwt.

For a beginner, it is easier to stick with CSV files (which in turn can
be exported/imported with Excel sheets.

example, how to get the input from such a file the most easiest way
(separator is comma, text is enclosed in "):

-- file content example
"userid1", "password1"
"userid2", "password2"
"userid3", "password3"

for line in f.readlines():
    csvLine = line.strip()) # get rid of newline
    arr.append( eval( "( %s )" % (csvLine) ) # interprets a line as a Python expression
f.close()
for e in arr: print e

now you have in your array a list of all lines containing the two given
values as a list in each entry:

user = arr[x][0]
pass = arr[x][1]

where x is a valid line number starting with 0

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