Help with syntax warnings

I

Ivan Shevanski

Here's a noob question for everyone (I'm not sure if my first message got
through, is had a "suspicious header" so sorry for double post is so), is
there a way to turn off syntax warnings or just make them not visible?


Thanks,
-Ivan

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
 
P

Peter Hansen

Ivan said:
Here's a noob question for everyone (I'm not sure if my first message
got through, is had a "suspicious header" so sorry for double post is
so), is there a way to turn off syntax warnings or just make them not
visible?

Not sure... what's a "syntax warning"?

Python has SyntaxError exceptions, which are raised during compilation
when a program can't even be compiled. They're definitely not warnings,
and making them invisible would generally be pointless, yet even so all
you would have to do is catch them and ignore them if that's what you
wanted to do. But did you mean SyntaxError, or something else?

-Peter
 
R

Robert Kern

Peter said:
Not sure... what's a "syntax warning"?

Python has SyntaxError exceptions, which are raised during compilation
when a program can't even be compiled. They're definitely not warnings,
and making them invisible would generally be pointless, yet even so all
you would have to do is catch them and ignore them if that's what you
wanted to do. But did you mean SyntaxError, or something else?

In [1]: SyntaxWarning?
Type: classobj
String Form: exceptions.SyntaxWarning
Namespace: Python builtin
Docstring:
Base class for warnings about dubious syntax.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
L

Leif K-Brooks

Ivan said:
is there a way to turn off syntax warnings or just make them not
visible?

import warnings
warnings.filterwarnings('ignore', category=SyntaxWarning)
 
P

Peter Hansen

Robert said:
Peter said:
Not sure... what's a "syntax warning"?

In [1]: SyntaxWarning?
Type: classobj
String Form: exceptions.SyntaxWarning
Namespace: Python builtin
Docstring:
Base class for warnings about dubious syntax.

Wow... Python detects "dubious syntax"? And here I thought programming
was rather black and white, it's right or it's wrong.

(He notes examples such as assigning to None and "unqualified exec is
not allowed in function" etc.)

I guess I've never accidentally hit one of those. Seems like, if I had,
I'd probably want to fix the problem rather than hide it, as with most
warnings from C compilers.

-Peter
 
R

Roel Schroeven

Ivan Shevanski schreef:
Here's a noob question for everyone (I'm not sure if my first message
got through, is had a "suspicious header" so sorry for double post is
so), is there a way to turn off syntax warnings or just make them not
visible?

Those warnings are something I have never seen and even have never heard
about, even though I now found out there's a section in the library
reference about them. It seems you can define filters to specify what
you want to do with the warnings; you can read all about it at
http://docs.python.org/lib/module-warnings.html
 
F

Fredrik Lundh

Peter said:
Wow... Python detects "dubious syntax"? And here I thought programming
was rather black and white, it's right or it's wrong.

SyntaxWarnings are issued for things that has never been valid nor well-
defined nor especially clever, but has been handled (in some more or less
reasonable way) by the CPython compiler. In practice, syntax warnings
will turn into errors in future releases.
(He notes examples such as assigning to None and "unqualified exec is
not allowed in function" etc.)

Compare and contrast:

Python 2.3.4 (#53, May 25 2004, 21:17:02)<stdin>:1: SyntaxWarning: assignment to None

Python 2.4.1 (#65, Mar 30 2005, 09:13:57)SyntaxError: assignment to None

</F>
 

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

Similar Threads

gmail access 1
python rounding problem. 15
modifying iterator value. 2
Class Help 6
noob question Letters in words? 8
open4 2
PHP in instant rails 1
WeBrick 4

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top