Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

32

# *-* coding: utf-8 *-* 

"""Implements the lingpy cache. 

 

Some operations in lingpy may be time consuming, so we provide a mechanism to cache the 

results of these operations. 

""" 

from __future__ import unicode_literals, print_function, absolute_import, division 

import pickle 

 

from clldutils.path import Path 

from appdirs import user_cache_dir 

from lingpy import __version__ 

 

 

DIR = Path(user_cache_dir('lingpy', version=__version__)) 

 

 

def path(filename): 

return DIR.joinpath(Path(filename).name + '.pkl') 

 

 

def load(filename): 

with path(filename).open('rb') as fp: 

return pickle.load(fp) 

 

 

def dump(data, filename): 

if not DIR.exists(): 

DIR.mkdir(parents=True) # pragma: no cover 

with path(filename).open('wb') as fp: 

pickle.dump(data, fp)