views:

69

answers:

4

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.

+1  A: 

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

ShinTakezou
being X the name of the python script you're interested in, you can call the interpreter (python) explicitly: `python -W ignore::DeprecationWarning /path/to/X`; /path/to/X can be changed into `$(which X)`
ShinTakezou
The problem is I have a bash script (i18ndude.sh) that calls i18ndude. But i18ndude isn't exatcly a Python script, I just call it from terminal typing "i18ndude", so I don't know where to put this call...
Somebody still uses you MS-DOS
and you can't modify the bash script? try `file $(which i18ndude)`; it should try to "guess" what i18ndude is. (So, you have a bash script calling i18ndude calling a python script?). (Doubt: do you know scripts does not require .sh, .py, .xyz extension?)
ShinTakezou
i18ndude - "/usr/local/bin/i18ndude: python script text executable". I have a bash script, I call it using "sh i18ndude.sh". This script calls i18ndude. Here is the script source: http://plone.org/documentation/manual/developer-manual/internationalization-i18n-and-localization-l10n/translating-text-in-code/i18ndude
Somebody still uses you MS-DOS
you then can change in the sh script every occurrence of i18ndude with `python -W ignore::DeprecationWarning /path/to/i18ndude`, and /path/to/i18ndude can be put into a var, like `ndude=$(which i18ndude) and so instead of /path/toi18ndude you write `$ndude`; if you can modify the sh script; otherwise, copy it in your bin or whereever you want, modify it and then call it like `sh ~/bin/i18ndude.sh` or alike; you could `chmod +x` it, put the `#! /bin/bash` as first line, eventually add `~/bin` to PATH, and run directly with `myi18ndude.sh` (change the name to avoid clashing with i18ndude.sh).
ShinTakezou
+1  A: 

You can temporarily suppress warnings:

If you are using code that you know will raise a warning, such as a deprecated function, but do not want to see the warning, then it is possible to suppress the warning using the catch_warnings context manager:

import warnings

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

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

While within the context manager all warnings will simply be ignored. This allows you to use known-deprecated code without having to see the warning while not suppressing the warning for other code that might not be aware of its use of deprecated code. Note: this can only be guaranteed in a single-threaded application. If two or more threads use the catch_warnings context manager at the same time, the behavior is undefined.

gimel
I didn't understand this solution. Where am I supposed to put this code? What is "context manager"? I can't edit the sources.
Somebody still uses you MS-DOS
If you can't edit the source, this method won't help.
gimel
Thanks anyway. I've searched python docs, but this solution wasn't what I was looking for, that's why I asked how to suppress something on command line.
Somebody still uses you MS-DOS
If you can't modify the source, write a script for your bin that calls it and use the `-W ignore::DeprecationWarning` option.
ShinTakezou
+1  A: 

If running as a script you could use:

#!/usr/bin/env python -W ignore::DeprecationWarning
the_void
+1  A: 

See cmdoption-W:

-W arg

Warning control. Python’s warning machinery by default prints warning messages to sys.stderr. A typical warning message has the following form:

file:line: category: message

By default, each warning is printed once for each source line where it occurs. This option controls how often warnings are printed.

Multiple -W options may be given; when a warning matches more than one option, the action for the last matching option is performed. Invalid -W options are ignored (though, a warning message is printed about invalid options when the first warning is issued).

gimel