Skip to content

Instantly share code, notes, and snippets.

View nkonin's full-sized avatar

Никита Конин nkonin

View GitHub Profile
@nkonin
nkonin / total_size.py
Last active April 27, 2017 09:34
Total size of Python objects
from __future__ import unicode_literals
from sys import getsizeof, stderr
from itertools import chain
from collections import deque
try:
from reprlib import repr
except ImportError:
pass
def total_size(o, handlers={}, verbose=False):
@nkonin
nkonin / serialize_instance.py
Created March 2, 2017 09:29
Serialize django model instance
from django.core import serializers
data = serializers.serialize("json", [model_instance])
with open("file", mode="w") as f:
f.write(data)