python collections模块中namedtuple()
2017-05-10 14:56
459 查看
最近看Ansible API中引用了collections的namedtuple()网上搜了一番后,发现是一个集合模块,提供了多种集合类。
本着用到哪里学哪里的原则,就来看看这个namedtuple()
就是定义了元组,让元组可以通过属性的方式;Ansible模板中自带的例子中,引用的就可以很明了的看到参数
In [1]: from collections import Callable Hashable Mapping namedtuple ValuesView _field_template _itemgetter Container ItemsView MappingView OrderedDict _abcoll _get_ident _repeat Counter Iterable MutableMapping Sequence _chain _heapq _repr_template defaultdict Iterator MutableSequence Set _class_template _imap _starmap deque KeysView MutableSet Sized _eq _iskeyword _sys提供了这些方法
本着用到哪里学哪里的原则,就来看看这个namedtuple()
In [1]: from collections import namedtuple In [2]: Option = namedtuple('Option',['user','password']) In [3]: option = Option('zhangsan','123') In [4]: option.user Out[4]: 'zhangsan' In [5]: option.password Out[5]: '123' In [6]: option Out[6]: Option(user='zhangsan', password='123')
就是定义了元组,让元组可以通过属性的方式;Ansible模板中自带的例子中,引用的就可以很明了的看到参数
相关文章推荐
- Python的collections模块及namedtuple详解
- Python的collections模块中namedtuple结构使用示例
- Python的collections模块中namedtuple结构使用示例
- python模块collections中namedtuple()的理解
- Python学习笔记(三十三)常用内置模块(2)collections_namedtuple_deque_defaultdict_OrderedDict_Counter
- python模块collections中namedtuple()的理解
- python模块介绍- collections(5)-OrderedDict 有序字典
- Python中Collections模块的Counter容器类使用教程
- python模块学习之数据结构--collections.counter
- Python 基础—— collections 模块
- Python collections 模块用法举例
- python学习笔记-Day03 -第一部分(collections,Counter,defaultdict,namedtuple)
- Python collections模块实例讲解
- [从头学python] 第04节 集合模块collections
- Python学习笔记-4(模块:collections、itertools、xml)
- 简介Python的collections模块中defaultdict类型的用法
- Python collections模块
- Python collections模块实例讲解
- Python模块: collections
- python中collections 模块里的defaultdict()函数