35 lines
590 B
Python
35 lines
590 B
Python
# Bryan Schumaker (8/7/2010)
|
|
|
|
from libsaria import path
|
|
import cPickle as pickle
|
|
|
|
PROTO = pickle.HIGHEST_PROTOCOL
|
|
|
|
def save(item, file, ext="pickle"):
|
|
file = "%s%s" % (path.join(path.sariadir(),file), ext)
|
|
savefile(item, file)
|
|
|
|
|
|
def savefile(item, file):
|
|
f = open(file, 'w')
|
|
p = pickle.Pickler(f, PROTO)
|
|
p.dump(item)
|
|
f.close()
|
|
|
|
|
|
def load(file, ext="pickle"):
|
|
file = "%s%s" % (path.join(path.sariadir(),file),ext)
|
|
return loadfile(file)
|
|
|
|
|
|
def loadfile(file):
|
|
if path.exists(file) == False:
|
|
return
|
|
f = open(file)
|
|
p = pickle.Unpickler(f)
|
|
item = p.load()
|
|
f.close()
|
|
return item
|
|
|
|
|