By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

-W: Python bug? Documentation bug?

P: n/a
It appears that the -W option on starting python doesn't work the same
as the warnings module. In particular, the "message" parameter is not
treated as a regular expression, but rather a string literal which must
appear at the beginning of a warning message in order to match. The
treatment of -W in "python -h" makes no mention of the warnings module
(and I actually couldn't find any definitive documentation on command
line switches), though the documentation for the warnings module does
say:

The interpreter saves the arguments for all -W options without
interpretation
in sys.warnoptions; the warnings module parses these when it is
first imported

That also kind of maybe implies that warnings is automatically imported
by the interpreter, but it doesn't actually say so.

How should this be treated?

=========
Here's an example of the problem. (I've reproduced it in version 2.5
also)

$ python -W ignore:whenThreaded
Python 2.4.2 (#2, Mar 10 2006, 15:10:56)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
>>from twisted.internet import reactor
/usr/local/lib/python2.4/site-packages/twisted/internet/base.py:245:
DeprecationWarning: threadable.whenThreaded is deprecated. Use
application-level logic instead.
threadable.whenThreaded(self.initThreads)
>>>
$ python -W ignore:'threadable.whenThreaded is deprecated. Use
application-level logic instead.'
Python 2.4.2 (#2, Mar 10 2006, 15:10:56)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
>>from twisted.internet import reactor
$ python -W ignore:threadable.whenThreaded
Python 2.4.2 (#2, Mar 10 2006, 15:10:56)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
>>from twisted.internet import reactor
Dec 13 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Clarence wrote:
It appears that the -W option on starting python doesn't work the same
as the warnings module. In particular, the "message" parameter is not
treated as a regular expression, but rather a string literal which must
appear at the beginning of a warning message in order to match. The
I must have gotten confused during my testing. The behavior is the same
whether coming from the command line or from within the program.
However, I see that the regular expression is being tested using
re.match rather than re.search. Does that seem correct to people? At
the least, that should be mentioned in the documentation.

Dec 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.