input command as global variable?

Asked by Shawn Robertson

I have decided that i would like to use inputs I have defined as global variables using the sikuli Settings class.

i created a script folder called "Settings"

and in that script i wanted to have:

def ts_settings():
       Settings.tsVersion = input("Enter your version ie.. 2013, 2014 etc:", "2014")

so that i could pull that value stored from user input in multiple scripts as long as I have imported the script containing that function and have one script sort of look like this:

import Settings
Settings.ts_settings()

App.open(r'c:\tssmoketest\\' +tsVersion)

Am i going about this the wrong way?

I dont want to have:

tsVersion = input("Enter your version ie.. 2013, 2014 etc:", "2014")

in each script prompting the user each time in the middle of a script.

thanks in advance for any help as always!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

--1. avoid name clashes
your own "Settings" script should be named differently. e.g. mySettings.sikuli

--2. usage case: input one time at start up

This only works when script is run from command line and in the IDE the first time the script is run.

# mySettings.sikuli
Settings.tsVersion = input("Enter your version ie.. 2013, 2014 etc:", "2014")

# in the script
import mySettings # the input is triggered

App.open(r'c:\tssmoketest\\' + Settings.tsVersion)

Come back, if this is not what you need

Revision history for this message
RaiMan (raimund-hocke) said :
#2

BTW:
App.open(r'c:\tssmoketest\' + Settings.tsVersion)

raw strings do not need \\ for one \

... and (I already talked about that I think ;-):

import os
myApp = os.path.join("c:", os.sep, "tssmoketest", Settings.tsVersion)
App.open(myApp)

so no messing around with \

Revision history for this message
Shawn Robertson (shawn-robertson) said :
#3

Both of those answered my question perfectly and Yes you did explain the raw string path not needing \ and to stay away from them.

hard habit to break :) thanks so much for your patient and help.

Many Thanks Raiman!

Revision history for this message
Shawn Robertson (shawn-robertson) said :
#4

Thanks RaiMan, that solved my question.