[Tutor] Tutor Digest, Vol 33, Issue 67

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Nov 17 02:56:01 CET 2006


>
> while True:  # use the boolean value, its clearer IMHO :-)
>    try:
>       name.append(...)
>       print name[-1]
>       i += 1
>    except WindowsError: pass
>
[some comments cut]
>
> Note that this call will create a new name list inside the recursive
> call. You probably need to do:
>
>           name += ListRegistryKeys(item)


Mutating the list while iterating over it is possibly bad.  That's why 
it's probably better to use a separate variable to collect the 
sub-results.

Concretely:

##################
>>> L = [1]
>>> for x in L:
...    L.append(x)
...
##################

is an infinite loop.


More information about the Tutor mailing list