Elegantly suppress Twill output in Python

565 Views Asked by At

I've recently been playing around with Twill and BeautifulSoup to do some basic screenscraping. However, it appears that one of the commands I'm using is printing a bunch of undesired output to the screen. Here's a quick snippet of the code I use to login to the site in question:

from twill.commands import *
from twill import get_browser

mybrowser = get_browser()
mybrowser.go(url)
mybrowser.showforms()
formvalue('1', 'email', email)
formvalue('1', 'password', password)
mybrowser.submit()
result = show()


At the moment, I'm using the "redirect_output()" function to pipe the undesired output to a garbage-filled text file...but this seems like a very hackish solution. Is there a more elegant way to avoid excessive printing with the commands above?

1

There are 1 best solutions below

1
Leonid Shvechikov On BEST ANSWER

My best idea is:

import os
f = open(os.devnull,"w")
twill.set_output(f)