hi to all ,
i have got this error when i try to write a str to a output.txt file
***********************************************************************************************************
i got this error
Traceback (most recent call last):
File "C:\Users\madhu\Desktop\yesnosplit.py", line 35, in <module>
f.write(x+"\n")
TypeError: can only concatenate list (not "str") to list
***********************************************************************************************************
My python Code: TO SPLIT THE SENTENCE AND SAVE IT TO A ANOTHER FILE
import re, math, collections, itertools
import nltk
from nltk.corpus import stopwords
import string
postext_filter=[]
negtext_filter=[]
alist=[]
stopwords=open('D:\stopwords.txt','r').read().split()
#reading pre-labeled input and splitting into lines
posSentences = open('D:\\yes.txt', 'r')
negSentences = open('D:\\no.txt', 'r')
posSentences = re.split(r'\n', posSentences.read())
negSentences = re.split(r'\n', negSentences.read())
posFeatures = []
negFeatures = []
#
http://stackoverflow.com/questions/367155/splitting-a-string-into-words-and-punctuation
#breaks up the sentences into lists of individual words (as selected
by the input mechanism) and appends 'pos' or 'neg' after each list
for i in posSentences:
posWords = re.findall(r"[\w']+|[.,!?;]", i)
posFeatures.append(posWords)
for i in negSentences:
negWords = re.findall(r"[\w']+|[.,!?;]", i)
negFeatures.append(negWords)
poslist=posFeatures
with open('output.txt','w')as f:
for x in poslist:
f.write(x+"\n")
**********************************************************************************************************
KINDLY HELP ME
THANKS IN ADVANCE
REGARDS
S.MADHU
RESEARCH SCHOLAR,
ANNA UNIVERSITY, CHENNAI
INDIA-s...@gmail.com
RE