Elnaz Salehzadeh Nobari Elnaz Salehzadeh Nobari - 2 years ago 152
Python Question

Tokenize not working with any string input

I previously posted about a string I extract from a link, for which I want to apply tokenize, with no luck. So tried a simplified example:
my command line is very simple:

a="Any Random text at all , nothing freaking works"
sentences = nltk.sent_tokenize(a)

I consistently get:

TypeError: Can't convert 'list' object to str implicitly

I have tried
, and checked :

>>> type(a)
<class 'str'>

is there something wrong with my Python? I have checked examples and this apparently should be working. Would really appreciate it if someone could run and see if they get results and if so, what might be wrong with my Python

Added image of error

Answer Source

It's the problem in nltk package itself. As in the picture, it is not the parameter passed in but literal [''] in nltk/data.py which is considered to be list and converting to string.

Re-install nltk package may help?

show the 69th line of nltk/data.py it should be path = []

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download