How to suppress "DeprecationWarning: Old style callback, use cb_func(ok,store) instead"

J

John Nagle

How do I suppress "DeprecationWarning: Old style callback, use cb_func(ok,
store) instead". A library is triggering this message, the library is being
fixed, but I need to make the message disappear from the output of a CGI
program.

John Nagle
 
P

Peter Otten

John said:
How do I suppress "DeprecationWarning: Old style callback, use
cb_func(ok,
store) instead". A library is triggering this message, the library is
being fixed, but I need to make the message disappear from the output of a
CGI program.

import warnings
warnings.filterwarnings("ignore", message="Old style callback, use
cb_func(ok, store) instead")

Peter
 
G

Gabriel Genellina

import warnings
warnings.filterwarnings("ignore", message="Old style callback, use
cb_func(ok, store) instead")

Or you can be more aggressive and filter out all DeprecationWarnings:
warnings.simplefilter("ignore",DeprecationWarning)
(same as using option -Wignore::DeprecationWarning on the python command
line)
 
N

Neil Cerutti

Or you can be more aggressive and filter out all DeprecationWarnings:
warnings.simplefilter("ignore",DeprecationWarning)
(same as using option -Wignore::DeprecationWarning on the python command
line)

Ah, yes! The null module. Python should have more of these. I
mean "shouldn't". ;)
 
P

Peter Otten

Gabriel said:
Or you can be more aggressive and filter out all DeprecationWarnings:
warnings.simplefilter("ignore",DeprecationWarning)
(same as using option -Wignore::DeprecationWarning on the python command
line)

The latter might be interesting for a cgi. I didn't mention it because I
didn't get it to work with my test case (importing sre) and Python's cgi
server. Trying again, I found that you must not quote the -W argument.

#!/usr/local/bin/python2.5 -Wignore:The sre module is deprecated, please
import re.

From that follows that you can pass at most one commandline arg.
If you are using

#!/usr/bin/env python2.5

python2.5 will be that single argument and no options are possible at all.
What might be the reasons for such a seemingly arbitrary limitation?

Peter
 
J

John Nagle

Thanks.

Actually, just copying the message into the string doesn't work; the
matching argument is a regular expression, so "(" has special meaning.
But the general idea is right.

John Nagle
 
G

Gabriel Genellina

The latter might be interesting for a cgi. I didn't mention it because I
didn't get it to work with my test case (importing sre) and Python's cgi
server. Trying again, I found that you must not quote the -W argument.

#!/usr/local/bin/python2.5 -Wignore:The sre module is deprecated, please
import re.

If you are using

#!/usr/bin/env python2.5

python2.5 will be that single argument and no options are possible at
all.
What might be the reasons for such a seemingly arbitrary limitation?

The shell parses that line, not Python, so you should look into its
documentation.

If one needs to disable the warning for all scripts, putting a call to
warnings.simplefilter on sitecustomize.py would help (of course, if one is
allowed to edit that file).
 
T

Thomas Bellman

Gabriel Genellina said:
En Sat, 03 Feb 2007 07:35:22 -0300, Peter Otten <[email protected]>
escribió:
The shell parses that line, not Python, so you should look into its
documentation.

Bzzt! In any modestly recent Unix version (meaning fifteen years
old or younger), it has been the kernel that parsed the #! line,
not the shell.

As for *how* the kernel parses that line, it varies between Unix
versions. Linux, at least versions 2.4 and 2.6, takes everything
after the interpreter and passes it as a single argument to the
interpreter, with leading and trailing whitespace stripped. Thus

#! /usr/bin/interpreter foo bar gazonk del

will give the parameter "foo bar gazonk del" to the interpreter.

SunOS 5.10 (aka Solaris 10) on the other hand, splits the line on
whitespace and passes only the first word as parameter, and would
thus give only "foo" to the interpreter for the same #! line.

I seem to remember having used some Unix flavor that allowed
multiple words as arguments, and thus passed the four words
"foo", "bar", "gazonk" and "del" as arguments for the above #!
line, but I don't remember what Unix that was.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top