Reputation: 13
I am trying to use textBlob with a text file input.
All examples I found online were of input in this sense:
wiki = TextBlob("Python is a high-level, general-purpose programming language.")
wiki.tage
I tried this:
from textblob import TextBlob
file=open("1.txt");
t=file.read();
print(type(t))
bobo = TextBlob(t)
bobo.tags
The code I tried did not work.
Upvotes: 1
Views: 3787
Reputation: 8144
This is a classic Unicode issue
Use
import sys
reload(sys)
sys.setdefaultencoding('utf8')
Then read the file
In this way you can use UTF-8
encoding/decoding format
this is outdated for Python 3.X
Upvotes: 2
Reputation: 3366
For Python3 guys:
import sys
from importlib import reload
reload(sys)
sys.getdefaultencoding() # use this for Python3
from textblob import TextBlob
url ='filename.txt'
file=open(url)
t=file.read()
print(type(t))
bobo = TextBlob(t)
bobo.tags
Upvotes: -1
Reputation: 1
You could also look into Unidecode.
https://pypi.python.org/pypi/Unidecode
from unidecode import unidecode
...
bobo = TextBlob(unidecode(t))
Upvotes: 0