This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients ezio.melotti, jacobidiego
Date 2010-07-13.08:25:59
SpamBayes Score 0.0013513172
Marked as misclassified No
Message-id <1279009562.8.0.673817010312.issue9240@psf.upfronthosting.co.za>
In-reply-to
Content
"for j in range(1,5), i in range(120,500,12):"
is equivalent to
"for j in (range(1,5), i in range(120,500,12)):"
so the sequence here is a tuple that contains range(1,5) as first element and "i in range(120,500,12)" as second element.
Since 'i' is needed before the loop starts to check if it's in range(120,500,12), if you don't define it, it raises a NameError.
If 'i' already had some value before, then the code works, but it doesn't do what you expect. I.e., this code:
>>> i = 0
>>> for j in (range(1,5), i in range(120,500,12)):
...   j,i
...

results in :
(range(1, 5), 0)
(False, 0)

because the first element of the sequence is range(1,5) so at the first iteration j = range(1,5) and since 'i' is untouched it's still 0, so the first line ends up being (range(1,5), 0).
At the second iteration the value of j is "i in range(120,500,12)" and since 'i' is 0 and 0 is not in range(120,500,12), that evaluates to False. So we have j = False and 'i' is still 0, hence the (False, 0) in the second line.

The different results are because probably you had 'i = <something>' in your program but not in the interpreter.

What you want is "for j, i in zip(range(packetlen+1), channels): ..." or possibly "for j, i in enumerate(channels): ...".

I'm not sure anything can be done in this case, except maybe require () in case the sequence contains an 'in', but I'm not sure it's worth doing it. 
I'll leave this open for a while to see if other developers have any comment.
History
Date User Action Args
2010-07-13 08:26:03ezio.melottisetrecipients: + ezio.melotti, jacobidiego
2010-07-13 08:26:02ezio.melottisetmessageid: <1279009562.8.0.673817010312.issue9240@psf.upfronthosting.co.za>
2010-07-13 08:26:00ezio.melottilinkissue9240 messages
2010-07-13 08:25:59ezio.melotticreate