Skip to main content

This is a python module that can hide any annoying warning messages from external C and C++ libraries in your python project

Project description

hide_warnings

This is a python module that can hide any annoying warning messages from external C and C++ libraries in your python project. There is a decorator called hide_warnings in this module, you can decorate any of your functions with this decorator, then no warning messages from external C and C++ libraries (if invoked) in your function will be printed to cmd/terminal.

Installation

pip install hide_warnings

Usage

For example, here is a function that when you run it, a warning message from external C and C++ libraries will be forcibly printed to cmd/terminal, which is very annoying, and in python normally it is hard to prevent the warning messages from non-python libraries, especially when the functions that throw out these warning messages are from compiled C and C++ executables (which means you cannot modify the code inside it) and you pretty much need to modify the source code and rebuild yourself to prevent these warning messages, which takes some work, and what's even worse is that some closed source C and C++ projects does not give out source code for you to build.

What we want is to directly hide the warning messages we do not want to see from external C and C++ libraries in our python projects.

def func(a, b):
    function_throw_external_warnings()
    result = a + b
    return result

>>> func(1, 2)
warning: This is some warnings from some external C and C++ functions
3

By decorating the function with hide_warnings, you can prevent these warning messages.

from hide_warnings import hide_warnings

@hide_warnings
def func(a, b):
    function_throw_external_warnings()
    result = a + b
    return result

>>> func(1, 2)
3

Note that by default, all of the printed messages will be prevented inside the decorated function, including python's own print functions. If you still want to use python's print function to print some messages that is useful to you, you can set the keyword argument out to False for the decorator, which makes the decorated function could still use python's own print function.

from hide_warnings import hide_warnings

@hide_warnings(out=False)
def func(a, b):
    function_throw_external_warnings()
    print('this is a message')
    result = a + b
    return result

>>> func(1, 2)
this is a message
3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hide_warnings-0.17.tar.gz (12.0 kB view details)

Uploaded Source

File details

Details for the file hide_warnings-0.17.tar.gz.

File metadata

  • Download URL: hide_warnings-0.17.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.9

File hashes

Hashes for hide_warnings-0.17.tar.gz
Algorithm Hash digest
SHA256 ab8682f5c89b413a95ce79c357c03d6ebace0031875c723f8b07784781a6d16c
MD5 c553cb2324805e2e175bdfe6615b827d
BLAKE2b-256 326f6f1af28a72e53eb9ea5947b2ec1180c3bc91eca8439e931a7d247368f525

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page