python - Global name "x" not defined using timeit -


i've got simple fibonacci function uses memoisation , works fine on own. when want time using timeit, "nameerror: global name 'memo' not defined", though is.

#!/usr/bin/python  import sys import timeit  memo = [0] * 100  def fibmem(n,memo):     #function things  x in range(1,40):      mytime2 = timeit.timer('fibmem('+str(x)+', memo)','from __main__ import fibmem')     delta2 = mytime2.timeit(1)     print str(x) + ' ' +str(delta2)     memo[:] = [] 

i've tried looking might be, of answers involve including from __main__ import , isn't problem here. i'm sure it's still scoping, new timeit, have no idea.

add memo list of variables imported __main__:

mytime2 = timeit.timer('fibmem({}, memo)'.format(x),'from __main__ import fibmem, memo') 

Comments