import sys, os
from BeautifulSoup import BeautifulSoup
"""Python script to open up each and every file in output_ann and take out the subjective or objective list"""
def processfile ( wparam, dirpath, namelist ):
""" waparam is the list is a dictionary of two file pointers """
for name in namelist:
""" only process file with name output """
if name == 'output':
fullpath = dirpath + '/' + name
f = open ( fullpath, 'r' )
data = f.read()
f.close()
soup = BeautifulSoup ( data )
# get the subjective sentences
lines = soup.findAll(attrs={"autoclass2" : "subj"})
for line in lines:
print line.encode ( "utf-8" )
#get the objective sentences
lines = soup.findAll(attrs={"autoclass2" : "obj"})
for line in lines:
print line.encode ( "utf-8" )
def main(argv=None):
flist = {}
flist['subj'] = open ( 'subjlist.txt' , 'w' )
flist['obj'] = open ( 'objlist.txt', 'w' )
os.path.walk ( os.getcwd() + '/output_anns', processfile, flist )
flist['subj'].close()
flist['obj'].close()
====
I get error:
print line.encode ( "utf-8" )
TypeError: 'NoneType' object is not callable