Thursday, April 28, 2022

[FIXED] How do you suppress Python DeprecationWarnings on Linux Terminal?

Issue

I installed i18ndude (an internationalization utility to be used in Plone) using easy_install.

When I try to run the utility i18ndude on 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 do I suppress these warning messages when calling the utility from command line? Is it possible? I know in theory I should install other Python interpreter, and call i18ndude from that, but I would like a simpler approach (like a parameter or something like that).

BTW, I'm using a i18ndude script from Plone official site.


Solution

Redirection can be used, but it would suppress all the messages sent to that "stream"; e.g.

i178ndude 2>/dev/null

sends to the null device the stream 2 (normally the stderr of a program, but deprecation warnings could be sent to other streams). This is the "fix it even though you don't know how" fix. Indeed there's an option, -W, that can be used like this: -W ignore::DeprecationWarning or simply -W ignore that ignores all warnings. You can write a script that call the python interpreter on your program, or more logically modify the #! of the prog with something like #!/usr/bin/env python -W ignore::DeprecationWarning



Answered By - ShinTakezou
Answer Checked By - David Marino (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.