Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help with syntax warnings

Reply
Thread Tools

Help with syntax warnings

 
 
Ivan Shevanski
Guest
Posts: n/a
 
      09-30-2005
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/g...ave/direct/01/

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      09-30-2005
Ivan Shevanski wrote:
> 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
 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      09-30-2005
Peter Hansen wrote:
> Ivan Shevanski wrote:
>
>>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?


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

--
Robert Kern


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

 
Reply With Quote
 
Leif K-Brooks
Guest
Posts: n/a
 
      09-30-2005
Ivan Shevanski wrote:
> is there a way to turn off syntax warnings or just make them not
> visible?


import warnings
warnings.filterwarnings('ignore', category=SyntaxWarning)
 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      09-30-2005
Robert Kern wrote:
> Peter Hansen wrote:
>>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
 
Reply With Quote
 
Roel Schroeven
Guest
Posts: n/a
 
      09-30-2005
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

--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      09-30-2005
Peter Hansen wrote:

> 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)
>>> None = "hello"

<stdin>:1: SyntaxWarning: assignment to None

Python 2.4.1 (#65, Mar 30 2005, 09:13:57)
>>> None = "hello"

SyntaxError: assignment to None

</F>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM
Turning off syntax warnings? Ivan Shevanski Python 0 09-30-2005 12:29 AM
use warnings; and use Warnings; give different results Ted Sung Perl Misc 1 08-30-2004 10:22 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57