Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105782

Re: How to make Python interpreter a little more strict?

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Newsgroups comp.lang.python
Subject Re: How to make Python interpreter a little more strict?
Date 2016-03-26 14:02 -0400
Organization IISS Elusive Unicorn
Message-ID <mailman.54.1459015336.28225.python-list@python.org> (permalink)
References <20160325150608.21c3827a@fujitsu>

Show all headers | View raw


On Fri, 25 Mar 2016 15:06:08 +0300, Aleksander Alekseev <afiskon@devzen.ru>
declaimed the following:

>Hello
>
>Recently I spend half an hour looking for a bug in code like this:
>
>eax@fujitsu:~/temp$ cat ./t.py 
>#!/usr/bin/env python3
>
>for x in range(0,5):
>    if x % 2 == 0:
>        next
>    print(str(x))
>
>eax@fujitsu:~/temp$ ./t.py 
>0
>1
>2
>3
>4
>
>Is it possible to make python complain in this case? Or maybe solve
>such an issue somehow else?

	By trying it out in the interactive window? (Note: Python 2.7 -- though
Python 3 doesn't need the "str(x)" either -- print will still ask for the
printable form of x.

>>> for x in range(0,5):
... 	if (x % 2) == 0:
... 		next
... 	print x
... 	
<built-in function next>
0
1
<built-in function next>
2
3
<built-in function next>
4
>>> 

>>> for x in range(0,5):
... 	if (x % 2) == 0:
... 		next()
... 	print x
... 
Traceback (most recent call last):
  File "<interactive input>", line 3, in <module>
TypeError: next expected at least 1 arguments, got 0
>>> 

>>> for x in range(0,5):
... 	if (x % 2) == 0:
... 		continue
... 	print x
... 
1
3
>>> 
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to make Python interpreter a little more strict? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-26 14:02 -0400

csiph-web