Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105782 > unrolled thread
| Started by | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| First post | 2016-03-26 14:02 -0400 |
| Last post | 2016-03-26 14:02 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How to make Python interpreter a little more strict? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-03-26 14:02 -0400
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2016-03-26 14:02 -0400 |
| Subject | Re: How to make Python interpreter a little more strict? |
| Message-ID | <mailman.54.1459015336.28225.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web