On 2006-09-27, OKB (not okblacke) <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:
>
>> To begin with this already fails:
>> 
>>>>> for i in xrange(Top):
>> ...   print i
>
>       What do you expect this to do?  Loop forever?

Yes that is what I would expect. If someone would ask me
to implement a function like xrange it would look something
like the following (*)

  def xrange(start=1, stop, step=1):

    while start < stop:
      yield start
      start += step

Since Top is supposed to be bigger than any other value this would
indeed loop forever. The only reason that this doesn't work with
the builtin, is because the builtin xrange insist on its arguments
being ints instead of allowing duck typing.

(*) Yes I know this isn't legal python. I just wrote it like this
to make the intention clear instead of putting in the code that
would actually behave like xrange with regards to its defaults.
IMO that would just detract from the actual code.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to