Module-level abstraction in Python

Sample code first.

# -*- coding: utf-8 -*-
# file: jukoro/

import cPickle

load = cPickle.load
loads = cPickle.loads

def dump(obj, f):
    return cPickle.dump(obj, f, protocol=cPickle.HIGHEST_PROTOCOL)

def dumps(obj):
    return cPickle.dumps(obj, protocol=cPickle.HIGHEST_PROTOCOL)

No magic inside - in our own project we've created module, the one to be used in place of cPickle from standart library.

As a result we've got an abstraction, which helps us to keep code DRY and improves code manageability.

I like this approach.

Last modified: 2015-01-30 17:40:00 +00:00 UTC