python3

Compression

1. compress

1
2
3
4
5
import zlib

...
zlib.compress(str.encode("utf-8"))
// compress requires byte

2. decompress

1
2
3
4
import zlib

...
zlib.compress(byte).decode("utf-8")

3. Dynamodb Binary

1
2
3
4
5
from boto3.dynamodb.types import Binary

# dynamodb.Binary Obj has attr: value
if isinstance(Item[column_name], Binary):
box_plot_str = zlib.decompress(Item[column_name].column.value).decode("utf-8")

Json

json -> str

1
json.dumps()

str -> json

1
json.loads()

File

1
2
3
file.open('sample.txt', 'w')
file.write()
file.close()

Decorator

1
2
3
4
5
6
7
8
9
def log(func):
def wrapper(*args, **kw):
print('call %s():' % func.__name__)
return func(*args, **kw)
return wrapper

@log
def now():
print('2015-3-25')