Giter Club home page Giter Club logo

hide_warnings's Introduction

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

hide_warnings's People

Contributors

rainbow-dreamer avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.