<html>
<body>
I'm puzzled by the below error msg. If I change the line in <tt>a2()</tt>
from<br><br>
<tt>l1 = [1,2,3]*100<br><br>
</tt>to<br><br>
<tt>l1 = [1,2,3]<br><br>
</tt>There is no problem. <br><br>
Why? And why isn't that line a problem for <tt>a1()</tt>?<br><br>
=========================================<br>
<tt>def a1():<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>return
l1.extend(l2)<br>
if __name__=='__main__':<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>l1 =
[1,2,3]*100<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>l2 =
[4,5,6]<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>from
timeit import Timer<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>t =
Timer(&quot;a1()&quot;, &quot;from __main__ import a1&quot;)<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>t1 =
t.timeit(number=10)<br><br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><br>
def a2():<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>l1 +=
l2<br>
if __name__=='__main__':<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>l1 =
[1,2,3]*100<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>l2 =
[4,5,6]<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>from
timeit import Timer<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>t =
Timer(&quot;a2()&quot;, &quot;from __main__ import a2&quot;)<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>t2 =
t.timeit(number=10)<br><br>
print &quot;t1:&quot;, t1<br>
print &quot;t2:&quot;, t2<br>
print &quot;t2/t1:&quot;, t2/t1<br><br>
Error msg:<br>
E:\PythonWork&gt;timing_2_stupidsV2.py<br>
Traceback (most recent call last):<br>
&nbsp; File &quot;E:\PythonWork\timing_2_stupidsV2.py&quot;, line 21, in
&lt;module&gt;<br>
&nbsp;&nbsp;&nbsp; t2 = t.timeit(number=10)<br>
&nbsp; File &quot;E:\Python25\lib\timeit.py&quot;, line 161, in
timeit<br>
&nbsp;&nbsp;&nbsp; timing = self.inner(it, self.timer)<br>
&nbsp; File &quot;&lt;timeit-src&gt;&quot;, line 6, in inner<br>
&nbsp; File &quot;E:\PythonWork\timing_2_stupidsV2.py&quot;, line 15, in
a2<br>
&nbsp;&nbsp;&nbsp; l1 += l2<br>
UnboundLocalError: local variable 'l1' referenced before assignment<br>
</tt>===================================================<br><br>
Thanks,<br><br>
Dick Moores</body>
</html>