The __main__
module is not the test
module, even though they come from the same file. When execution hits
from test import dictComp
test.py
executes again, this time as the test
module instead of the main
module. (When execution hits that line a second time, test
is already being imported, so the file doesn't run a third time.)
It's good practice to put stuff like your timeit
call in an if __name__ == '__main__'
guard:
if __name__ == '__main__':
t = timeit.timeit(...)
print(t)
If you don't, then definitely import from __main__
as opposed to from test
.