Un1
Un1

Reputation: 4132

How do you disable print log of an external library's function?

Problem

I'm importing nltk and downloading data for it:

import nltk
nltk.download('averaged_perceptron_tagger')

The problem is, every time I run the program, nltk.download displays the log in the console:

[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data]     C:\Users\f\AppData\Roaming\nltk_data...
[nltk_data]   Package averaged_perceptron_tagger is already up-to-
[nltk_data]       date!

Question

Is there a way to prevent it? It's a console program and I'd like it to show only the stuff I want it to.

Upvotes: 3

Views: 1718

Answers (2)

Naga kiran
Naga kiran

Reputation: 4607

you can also pass quiet=True while downloading

import nltk
nltk.download('wordnet', quiet=True)

Upvotes: 6

shiredude95
shiredude95

Reputation: 560

You should remove the nltk.download() call from your code after downloading the required packages once. By keeping the line you are essentially downloading it each time your run the program and hence the log message.

Upvotes: 1

Related Questions