[Python-ideas] Add 'use warnings' directive, like in Perl
Eduard Bondarenko
eduardbpy at gmail.com
Tue Feb 10 18:24:47 CET 2015
Dear Ian Cordasco,
> So as a maintainer/contributor to three of those I agree. But they're
> external dependencies which I sense is something you don't want.
>
> The reality is that you can compile this code with some standard
> library modules and they'll give you the feedback you want. If you
> were to run this code you'd get a NameErrors for the first line where
> you expect a warning and you would get a SyntaxError for the second
> else statement after the first. pyflakes and flake8 turn those into
> error codes for you. So really, python already comes with the warnings
> on because doing
>
> $ python test.py
>
> Would first result in a SyntaxError (because of your else following
> the first else) and then once that's been fixed, you'd get a
> NameError.
>
> Disclaimer: I didn't actually run the code so I may have the order of
> errors wrong, but I think this is roughly correct.
I am sorry..I mean:
#!/usr/bin/python
word = raw_input("Enter line : ")
if word == "hello":
print ("You enter \'hello\'")
else:
if world == "buy": #Error! should be word not world
print "Buy"
else:
dasdas
We will not have a problem with else.
Okay, we can split this example:
The first part is:
#!/usr/bin/python
*word* = raw_input("Enter line : ")
if *word* == "hello":
print ("You enter \'hello\'")
else:
if *world* == "buy": *#Error! should be word not world*
print "Buy"
*"NameError: name 'world' is not defined" - only in case if the word !=
'hello'*!!
The second one:
#!/usr/bin/python
*word* = raw_input("Enter line : ")
if *word* == "hello":
print ("You enter \'hello\'")
else:
if *word* == "buy": #Now correct!
print "Buy"
else
iamnotfunction *#Error*
*"NameError: name 'iamnotfunction' is not defined" only in case if word !=
'hello' and word != "buy"*!!
So I can type whatever I want in else block and someone can detect it after
the several years..
And the first thing that I have to do programming in Python is to download
analyser tool..I understand the importance of static analyser tools, but in
this case (to check simple things like a variables and functions names) it
is like "To use a sledge-hammer to crack a nut.".
Many thanks!
- Eduard
PS. Within C++ or other languages I should use static analyser tools to
check real bug-prone situation, but in new, modern Python I should use
third-party tools to check the real simple errata.
Maybe I do not understand something..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150210/beff0031/attachment.html>
More information about the Python-ideas
mailing list