swarupmishal
swarupmishal

Reputation: 55

How to use glob to read and open file from NLTK package using Python?

I am trying this code, but it doesn't seem to work.

My program:

from nltk.corpus import gutenberg
import glob
glob.glob("gutenberg/*.txt")

output:

[]

Upvotes: 0

Views: 176

Answers (1)

Lost
Lost

Reputation: 1008

Is there a reason you want to glob the .txt files? Based on NLTK Accessing Text you can get a list of the file ids with gutenberg.fileids()

Glob would seem more useful if you were trying to find some subset of the fileids as opposed to getting the complete list which it looks like you are trying to do.

Upvotes: 1

Related Questions