Heisenberg strikes again!
Duncan Booth
duncan at NOSPAMrcp.co.uk
Thu Sep 11 04:46:54 EDT 2003
"David C. Fox" <davidcfox at post.harvard.edu> wrote in
news:nRM7b.311656$Oz4.100417 at rwcrnsc54:
>> throwaway = matches[0] # <--- Comment out this line
>
> When comp is called with state == 0, matches is still referring to the
> local list which is not empty (unless there were no matches to the
> text), so this line does indeed do nothing. However, when comp is
> called with state != 0, this line refers to the global matches list,
> which is empty, so it raises an IndexError, and the following line is
> not reached.
Not quite true there. Whether or not state is 0, this line always tries to
access the local variable 'matches'. If you assign to a variable anywhere
in a function (and don't declare it global), then all accesses in the
function are to the local variable, not the global.
Of course the effect is basically the same, the function throws an
exception either way, its just a different exception.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list