I have this large script ( I will post the whole thing if I have to but it is very big) which starts off okay when I run it but it immediatly gives me 'TypeError: cannot concatenate 'str' and 'NoneType' objects' when it comes to this last bit of the code:
with open("self.txt", "a+") as f:
f = open("self.txt", "a+")
text = f.readlines()
text_model = markovify.Text(text)
for i in range(1):
tool = grammar_check.LanguageTool('en-GB')
lin = (text_model.make_sentence(tries=800))
word = ('' + lin)
matches = tool.check (word)
correct = grammar_check.correct (word, matches)
print ">",
print correct
print ' '
f = open("self.txt", "a+")
f.write(correct + "\n")
I have searched everywhere but gotten nowhere. It seems to have something to do with: word = ('' + lin)
. but no matter what I do I can't fix it. What am I doing wrong?
"string" + "string"
where one of the strings is in fact not a string but aNoneType
, possibly the one that is the return of a function. – Nae Nov 21 '17 at 0:38text_model.make_sentence()
can returnNone
. You either have to fix that function (so it always returns a string) or check forNone
in this code. – user8651755 Nov 21 '17 at 0:39