python 2.7的备忘录库 [英] memoization library for python 2.7

查看:85
本文介绍了python 2.7的备忘录库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到python 3.2在functools库中作为装饰器具有记忆. http://docs.python.org/py3k/library/functools.html #functools.lru_cache

I see that python 3.2 has memoization as a decorator in functools library. http://docs.python.org/py3k/library/functools.html#functools.lru_cache

很遗憾,它尚未回迁到2.7.有什么特定的原因可以解释为什么它在2.7中不可用?是否有任何第三方库提供相同的功能,或者我应该编写自己的库?

Unfortunately it is not yet backported to 2.7. Is there any specific reason as why it is not available in 2.7? Is there any 3rd party library providing the same feature or should I write my own?

推荐答案

有什么特殊的原因为什么它在2.7中不可用?

Is there any specific reason as why it is not available in 2.7?

@Nirk 已经提供了原因:不幸的是,2.x行仅收到错误修复,并且新功能是仅针对3.x开发.

@Nirk has already provided the reason: unfortunately, the 2.x line only receive bugfixes, and new features are developed for 3.x only.

有没有提供相同功能的第三方图书馆?

Is there any 3rd party library providing the same feature?

repoze.lru 是适用于Python 2.6,Python 2.7和Python 3.2.

repoze.lru is a LRU cache implementation for Python 2.6, Python 2.7 and Python 3.2.

文档和源代码可在 GitHub 上找到.

Documentation and source code are available on GitHub.

简单用法:

from repoze.lru import lru_cache

@lru_cache(maxsize=500)
def fib(n):
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)

这篇关于python 2.7的备忘录库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆