Besides @traceur's point about the indentation error, here's how you can simplify the code dramatically:
from mechanize import Browser
from bs4 import BeautifulSoup
mech = Browser()
url = "http://en.wikipedia.org/wiki/Hybrid_electric_vehicles_in_the_United_States"
soup = BeautifulSoup(mech.open(url))
table = soup.find("table", class_="wikitable")
for row in table('tr')[1:]:
print "|".join(col.text.strip() for col in row.find_all('th'))
Note that instead of using from BeautifulSoup import BeautifulSoup
(3rd version of BeautifulSoup), you'd better use from bs4 import BeautifulSoup
(4th version), since the 3rd version is no longer maintained.
Also note that you can pass mech.open(url)
directly to the BeautifulSoup
constructor instead of manually reading it.
Hope that helps.