Python
- 5 ответов
- 0 вопросов
2
Вклад в тег
from itertools import chain
l = [['foo'], ['bar']]
' '.join(chain.from_iterable(l))
class MyClass(date):
__slots__ = '_expiry',
def __new__(cls, m_year, m_month, m_day, expiry=None, *args, **kwargs):
return super(MyClass, cls).__new__(cls, m_year, m_month, m_day)
def __init__(self, m_year, m_month, m_day, expiry=None, *args, **kwargs):
if expiry:
self._expiry = expiry
else:
self._expiry = date(m_year, m_month, m_day)
@property
def expiry(self):
return {'year': self._expiry.year,
'month': self._expiry.month,
'day': self._expiry.day}
>>> q = MyClass(2015, 5, 5, expiry=date(2015, 5, 1))
>>> print(q.expiry)
>>> {'year': 2015, 'day': 1, 'month': 5}