python中的快速缓存

2024-06-26 13:30:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我在问一个非常基本的问题。 我查阅了dict的文件如下:

In [1]: ?dict
Init signature: dict(self, /, *args, **kwargs)
Docstring:
dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object's
    (key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
    d = {}
    for k, v in iterable:
        d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
    in the keyword argument list.  For example:  dict(one=1, two=2)
Type:           type
Subclasses:     OrderedDict, defaultdict, Counter, _EnumDict, Bunch, Config, Struct, ColorSchemeTable, FastDictCache, _CharSizesCache, ...

上面我知道了dict有哪些子类。我使用了OrderedDictdefaultdictCounterBunch,但是我在FastDictCache上找不到任何在线资源

python中的FastDictCache是什么?哪个包裹里有?如何使用它


Tags: theinnewdictionaryvaluecounteriterablemapping
1条回答
网友
1楼 · 发布于 2024-06-26 13:30:17

正如评论所说:

  • 子类列表来自当前存在的对象,通过cls.__subclasses__()
>>> class Foo(dict):
...     pass
...
>>> dict.__subclasses__()
[
  <class 'collections.OrderedDict'>,
  <class 'collections.defaultdict'>,
  <class 'collections.Counter'>,
  <class '__main__.Foo'>
]
>>>

相关问题 更多 >