@lru_cache on functions with no arguments

Ian Kelly ian.g.kelly at gmail.com
Thu Aug 3 14:20:50 EDT 2017


On Thu, Aug 3, 2017 at 12:17 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Thu, Aug 3, 2017 at 11:18 AM, Serhiy Storchaka <storchaka at gmail.com> wrote:
>> $ ./python -m timeit -s 'import sys; sys.modules["_functools"] = None; del
>> sys.modules["functools"]; from functools import lru_cache; f =
>> lru_cache(maxsize=None)(int)' -- 'f()'
>> 100000 loops, best of 5: 3.39 usec per loop
>
> Interesting, I had tried that and it didn't work for me:
>
> $ python3.6 -m timeit -s 'import sys; sys.modules["_functools"] =
> None; del sys.modules["functools"]; from functools import lru_cache; f
> = lru_cache(maxsize=None)(int)' -- 'f()'
> Could not import runpy module
> Traceback (most recent call last):
>   File "/usr/lib/python3.4/runpy.py", line 14, in <module>
>     import importlib.machinery # importlib first so we can test #15386 via -m
>   File "/usr/lib/python3.4/importlib/__init__.py", line 34, in <module>
>     _w_long = _bootstrap._w_long
> AttributeError: module 'importlib._bootstrap' has no attribute '_w_long'

Never mind, it's fine now. In the future I should remember not to run
python3.6 from the /usr/lib/python3.4 directory. =)



More information about the Python-list mailing list