打开文本文件作为 textblob 的输入
Open text file as input to textblob
我正在尝试将 textBlob 与文本文件输入一起使用。
我在网上找到的所有例子都是这种意义上的输入:
wiki = TextBlob("Python is a high-level, general-purpose programming language.")
wiki.tage
我试过这个:
from textblob import TextBlob
file=open("1.txt");
t=file.read();
print(type(t))
bobo = TextBlob(t)
bobo.tags
我试过的代码没有用。
这是经典Unicode issue
使用
import sys
reload(sys)
sys.setdefaultencoding('utf8')
然后读取文件
这样就可以使用UTF-8
encoding/decoding格式
你也可以看看 Unidecode。
https://pypi.python.org/pypi/Unidecode
from unidecode import unidecode
...
bobo = TextBlob(unidecode(t))
Python3 个人:
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
我正在尝试将 textBlob 与文本文件输入一起使用。
我在网上找到的所有例子都是这种意义上的输入:
wiki = TextBlob("Python is a high-level, general-purpose programming language.")
wiki.tage
我试过这个:
from textblob import TextBlob
file=open("1.txt");
t=file.read();
print(type(t))
bobo = TextBlob(t)
bobo.tags
我试过的代码没有用。
这是经典Unicode issue
使用
import sys
reload(sys)
sys.setdefaultencoding('utf8')
然后读取文件
这样就可以使用UTF-8
encoding/decoding格式
你也可以看看 Unidecode。
https://pypi.python.org/pypi/Unidecode
from unidecode import unidecode
...
bobo = TextBlob(unidecode(t))
Python3 个人:
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