Closures / Blocks in Python

Wildemar Wildenburger wildemar at freakmail.de
Wed Jul 25 18:21:32 CEST 2007


Jeff wrote:
> # Generic counter
> def counter(min=None, max):
>   if not min:
>     min = 0
>   for i in xrange(min, max):
>     yield i
>     i = i + 1
>   
Just for the record:
 >>> # Generic counter
... def counter(min=None, max):
...   if not min:
...     min = 0
...   for i in xrange(min, max):
...     yield i
...     i = i + 1
...
  File "<stdin>", line 2
SyntaxError: non-default argument follows default argument


You'd have to add a little more parameter-checking for this to work like 
you intend.
/W



More information about the Python-list mailing list