How do you suppress Python DeprecationWarnings on a Linux terminal?

I installed i18ndude(the internationalization utility that will be used in Plone) with easy_install.

When I try to run the utility i18ndudeon my terminal, I get:

/usr/local/lib/python2.6/dist-packages/i18ndude-3.1.2-py2.6.egg/i18ndude/odict.py:7: DeprecationWarning: object.__init__() takes no parameters
  dict.__init__(self, dict)

How can I suppress these warning messages when invoking the utility from the command line? Is it possible? I know that theoretically I should install another Python interpreter and call i18ndude from this, but I need a simpler approach (like a parameter or something like that).

By the way, I am using a i18ndudescript from the official Plone website .

+3
source share
4 answers

You can use redirection, but it will suppress all messages sent to this "stream"; eg.

i178ndude 2> / dev / null

sends stream 2 to the null device (usually stderr programs, but obsolescence warnings can be sent to other threads). This is a "fix, even if you do not know how to" fix it. Indeed, there is the -W option, which can be used as follows: -W ignore::DeprecationWarningor simply -W ignore, which ignores all warnings. You can write a script that calls the python interpreter in your program, or more logically change the #!program with something like#!/usr/bin/env python -W ignore::DeprecationWarning

+4
source

If you are using a script, you can use:

#!/usr/bin/env python -W ignore::DeprecationWarning
+4

:

, , , , , , , catch_warnings:

import warnings

def fxn():
    warnings.warn("deprecated", DeprecationWarning)

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    fxn()

. , , . : . catch_warnings , undefined.

+3

. cmdoption-W:

-W arg

. Pythons sys.stderr. :

file: line: category: message

By default, each warning is printed once for each line of the source where it occurs. This setting determines how often alerts are printed.

You can specify several W parameters; when a warning matches several parameters, the action is taken for the last matching option. Invalid -W options are ignored (although the first time a warning is issued, a warning message about invalid parameters is displayed).

+1
source

Source: https://habr.com/ru/post/1750526/


All Articles