python - Using show() with twill spams the console with HTML -


i've been using fuction twill.commands.show() raw html page. run every 5 seconds. every time function ran, spams console mentioned webpages raw html. need use console debugging, , since console filled html constantly, doing impossible. since show() programmed print html , return string, have edit twill, way beyond skillset, , makes program incompatible on other devices. although saving , reading file on , on might work, seems impractical every 5 seconds.

code:

go('http://google.com/') html=show() 

again, twill has save_html, used save file, i'm doing every 5 seconds , slow program/computer, if it's being run on older os.

thanks!

twill writes stdout default.

you can use twill.set_output(fp) redirecting standard output. there're several possible implementations doing this:

write stringio:

from stringio import stringio sio = stringio() twill.set_output(sio) html = show() # html+'\n' == sio.getvalue() 

or /dev/null:

import os null = open(os.devnull, 'w') twill.set_output(null) html = show() # writing /dev/null or nul null.close() 

or nothing @ all:

class devnull(object):     def write(self, str):         pass twill.set_output(devnull()) html = show() 

or other writable file-like python object of liking.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -