python 元组转成类
- 2019 年 10 月 7 日
- 筆記
collections.namedtuple
from collections import namedtuple Subscriber = namedtuple('Subscriber', ['addr', 'joined']) sub = Subscriber('[email protected]', '2012-10-19') sub Subscriber(addr='[email protected]', joined='2012-10-19') sub.addr '[email protected]' sub.joined '2012-10-19'