-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbite_13.py
More file actions
31 lines (23 loc) · 819 Bytes
/
bite_13.py
File metadata and controls
31 lines (23 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Online Python - IDE, Editor, Compiler, Interpreter
from collections import namedtuple
import datetime
import json
from typing import NamedTuple
blog = dict(name='PyBites',
founders=('Julian', 'Bob'),
started=datetime.datetime(year=2016, month=12, day=19),
tags=['Python', 'Code Challenges', 'Learn by Doing'],
location='Spain/Australia',
site='https://pybit.es')
# define namedtuple here
Blog = namedtuple('Blog', blog.keys())
def dict2nt(dict_):
return Blog(**dict_)
# Define a custom function to serialize datetime objects
def serialize_datetime(obj):
if isinstance(obj, datetime.datetime):
return obj.isoformat()
def nt2json(nt):
start = nt._asdict()
end = json.dumps(start, default=serialize_datetime)
return end