[twill] Variables etc. between Python and twill
Titus Brown
titus at caltech.edu
Thu Aug 3 09:59:09 PDT 2006
On Thu, Aug 03, 2006 at 07:06:45PM +0530, Swati Bendale wrote:
-> Hi Titus,
->
-> I am trying to set environment variable in twill script and trying to
-> access the variable in python script. Somehow it gives me error saying
-> setenv is not a twill command. could you pl. suggest procedure to set
-> multiple environment variables in twill scripts which could be available in
-> Python script and procedure to get it in Python script.
->
-> Is there any method/procedure to set a string variable in twill script and
-> access it in Python script. I was thinking of using environment variable to
-> set string in twill and accessing it in Python script. It's urgent!!! pl.
-> help.
Hi, Swati,
if I understand you correctly, you need to set/retrieve twill variables
from Python, and set/retrieve Python environment variables from twill.
Here are some code snippets that might help:
---
import twill
# set a global variable from Python using commands
twill.commands.setglobal('a', '5')
# retrieve a global variable from twill in Python
globals_dict, locals_dict = twill.namespaces.get_twill_glocals()
print eval('a', globals_dict, locals_dict)
# set a global variable from Python using dictionary
globals_dict['b'] = '6'
twill.execute_string('echo $b')
# set an environment variable
twill.commands.run('import os; os.environ["test"] = "hello"')
# retrieve an environment variable
twill.commands.run('global x; x = os.environ.get("test")')
twill.execute_string('echo $x')
---
Note that 'twill.commands.run' can be used directly from twill, e.g.
>>> run 'global x; x = os.environ.get("test")'
>>> echo $test
cheers,
--titus
More information about the twill
mailing list