[twill] The wonders of twill's run command
Howard B. Golden
howard_b_golden at yahoo.com
Tue Mar 24 16:38:39 PDT 2009
Hi Titus and everyone,
I'm hesitant to admit that I've only started to use twill. I'm blown away!
The one suggestion I have is to add more documentation and examples for the run command, since its capabilities may not be obvious:
a. import any module:
run "import os"
# now the os module is available in future run commands
run "home = os.environ['HOME']"
# outputs: your home directory name
b. set twill's global and local variables:
run "import time; lt = time.localtime(); local_date = '%04d-%02d-%02d' % (lt, lt, lt)"
# $lt is still the Python time structure (not a string!)
# outputs: 2009-03-24 (or the current date in local time)
c. do something to the html:
run "b = get_browser(); my_page = b.get_html(); page_length = repr(len(my_page))"
# $my_page now contains the html for further processing
# outputs: length of current page. (you must use repr to get a string.)
One question: Currently, the echo command has this code to deal with the supplied strings:
strs = map(str, strs)
This code will only work for strings and string-like objects. If echo used this line instead:
strs = map(repr, strs)
would it still do what you expect (while also accepting other object types)?
Thank you, Titus and all contributors, for a fantastic package!
More information about the twill