How to provide user input to sikuli script from a file

Asked by Sathyamoorthy on 2012-07-25


I have to pass several inputs to sikuli script, like username, IP address, Machine name, OS name. So its another painful activity to type each value in input window.
So I want to pass these values from a file. Please anyone give me steps to do that

Thanks in Advance

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

the basics:

--- make a comma separated text file like

user1,,themachine,Windows 7
user2,,themachine2,Windows 7

and so on

--- read the file and get the records/fields

fname = "absolute path to textfile"
f = open(fname)

for line in f.readlines()
    (user, ip, machine, system) = line.strip().split(",")
    print "current:" user, ip, machine, system
    # put your code here


pyCoder (validcode-ye) said : #2

#inside application

config = ConfigParser.ConfigParser()'config.ini')
username = config.get('settings','username')
ipAddress = config.get('settings','ipAddress')

inside 'config.ini'

username = Bob Marley
ipAddress = 190.943.1

RaiMan (raimund-hocke) said : #3

@ pyCoder
good finding - thanks. I will make it a faq.

But you missed the needed
import ConfigParser
at the beginning.

BTW: for the given case this is not the best solution, since he wants to input more than one option set with the same structure but different content.
This is more a case for a CSV solution, which might be supported by the Python CSV module.

pyCoder (validcode-ye) said : #4

refined.. your right RaiMan, it's depends on what op needs... if it's like a hundered entries csv method might be better. i took it as a config type. basically if you have thousands of entries use the csv module. but it's achevable as shown below.



#inside application, configparser example

import ConfigParser

config = ConfigParser.ConfigParser()'config.ini')
username1 = config.get('user1','username')
username2 = config.get('user2','username')

#inside 'config.ini'

user = Guido Van Rossum
ip =
machineName= Guido's Machine
system = Ubuntu

user = Bob Marley
ip =
machineName= Bob's Machine
system = windows 7

pyCoder (validcode-ye) said : #5

username1 = config.get('user1','username')

should be

username1 = config.get('user1','user')

i hate how this sight doesn't allow edits.

RaiMan (raimund-hocke) said : #6

--- i hate how this sight doesn't allow edits.
Do not ask RaiMan how he hates it ;-)

pyCoder (validcode-ye) said : #7

lmao *site ugh.....

Thanks for the answers .. If I have to pass values to for loop also how to do that .

Problem solved

Shafiq Khan (srk8887) said : #10

def UserName():
    config = ConfigParser.ConfigParser()
    myFilePath = os.path.join(getBundlePath(),'settings.ini')
    print "My config file is located at: " + myFilePath

    with open(myFilePath,'r') as configfile:
        return config.get('user1','user')

print UserName()

Now, on to encrypting password on config file...

panadol007 (panadol007) said : #11

None of above solutions help in my MAC.
But the simple solution is to give the config file a full path, then it works:

#inside application:
import ConfigParser

config = ConfigParser.ConfigParser()'/Users/markkhor/Desktop/Development/Sikuli/Testing/SimpleTest/config.ini')
username1 = config.get('user1','user')

print username1

#inside config.ini
user = Guido Van Rossum
ip =
machineName= Guido's Machine
system = Ubuntu