no side effects
holger krekel
pyth at devel.trillke.net
Wed Jan 8 10:30:19 EST 2003
"Martin v. L?wis" wrote:
> holger krekel wrote:
> > 'i' might not be local but usually it is. When answering
> > newcomer questions i try to refrain from talking in language
> > lawyer details (as much as possible). I only tried to explain the
> > for-loop from the viewpoint of names bound to objects. I didn't
> > want to compare iteration protocols between python and C++ just
> > to explain that.
>
> I'm uncertain though whether an actually incorrect explanation helps the
> newcomer.
Of course, it shouldn't be incorrect. I don't think i actually was.
> Namespaces are totally irrelevant for this feature of the for loop.
Depends on your background. *If* somebody e.g. thinks that
for i in range(3):
print i
i = 3
is somewhat equivalent to C's
int i;
for (i=0 ; i<3 ; i++) {
printf("%d\n", i);
i = 3;
}
then IMHO my explanation serves well and talking about underlying
iterator protocols wouldn't help too much.
Why is the way the python for-loop gets to the next *value*
more important than understanding that python works with
name-object bindings everywhere? And what is so wrong
about this (*)?
slightly irritated,
holger
(*) see http://www.python.org/dev/doc/devel/ref/naming.html
for further details.
More information about the Python-list
mailing list