diff options
author | Peng Wu <alexepico@gmail.com> | 2011-07-15 16:44:46 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-07-15 16:44:46 +0800 |
commit | fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3 (patch) | |
tree | 1ad6db8b71997c918c7cc81b8589721edd947d80 /lib | |
parent | 61be0be890cba36e4b6915d2a1311c3a946cbb29 (diff) | |
download | trainer-fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3.tar.gz trainer-fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3.tar.xz trainer-fe2d8789c1b1ba6fab743ea7ff9d16c4306e46e3.zip |
begin to write segment.py
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/utils.py b/lib/utils.py index b2e6f10..156fbaf 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1,3 +1,4 @@ +import os import json #Utils @@ -17,8 +18,18 @@ def write_file(outfile, data): #JSON Load/Store def load_status(infile): - return json.loads(read_file(infile)) + data = '{}' + if os.access(infile, os.R_OK): + data = read_file(infile) + + return json.loads(data) def store_status(outfile, obj): write_file(outfile, json.dumps(obj)) return + +#test case +if __name__ == '__main__': + obj = load_status('/tmp/test.status') + print(obj) + store_status('/tmp/test.status', obj) |