KhaledMaged
KhaledMaged

Reputation: 469

Hide a specific output message from terminal when excuting a python script?

I'm excuting a python script that utilizes patoollibrary (a library for creating/extracting compressed archives).

The thing is that when I run the script, it gives me the following lines:

patool: Extracting D:/xx/xx/xx.xml.gz
patool: running "C:\Program Files\7-Zip\7z.EXE" e -o D:/xx/xx/ -- D:/xx/xx/xx.xml.gz
patool: ... D:/xx/xx/ -- xx.xml.gz extracted to D:/xx/xx/

These obviusly are not error lines. They just tell me what's going on. I need to hide these lines when excuting the script. But ONLY this message, I mean NOT other type of messages, like error messages for example.

Upvotes: 2

Views: 1489

Answers (2)

Paladini
Paladini

Reputation: 4572

After some reading I've found an easy fix to this annoying problem. The fix is in their documentation. As you can see in their source code (at this time, line 679), patool only print messages when verbosity option is equal or greater than 0:

def extract_archive(archive, verbosity=0, outdir=None, program=None, interactive=True):
    """Extract given archive."""
    util.check_existing_filename(archive)
    if verbosity >= 0:
        util.log_info("Extracting %s ..." % archive)
    return _extract_archive(archive, verbosity=verbosity, interactive=interactive, outdir=outdir, program=program)

So, in order to fix your problem and hide all standard prints from patool use:

patoolib.extract_archive(path_to_file, outdir=path_to_unzip, verbosity=-1)

Instead of:

patoolib.extract_archive(path_to_file, outdir=path_to_unzip)

Hope this helps :)

Upvotes: 5

loar
loar

Reputation: 1745

I think what you need is to use a logging library (like logging). Thus, you isolate the information due to the script's behavior (info/succes/errors) from the output of the script (what you want to show).

Upvotes: 0

Related Questions