diff options
author | Peng Wu <alexepico@gmail.com> | 2011-07-15 13:42:40 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-07-15 13:42:40 +0800 |
commit | 76503e97efe8a70f1ce888427c1d4c0d2486548a (patch) | |
tree | 1fc059e5f22630c286cc684a05aa0226ecbf1091 | |
parent | 2c28a5c87d904f69dcc554070038995390903f76 (diff) | |
download | trainer-76503e97efe8a70f1ce888427c1d4c0d2486548a.tar.gz trainer-76503e97efe8a70f1ce888427c1d4c0d2486548a.tar.xz trainer-76503e97efe8a70f1ce888427c1d4c0d2486548a.zip |
begin to write utils.py
-rw-r--r-- | lib/myconfig.py | 12 | ||||
-rw-r--r-- | lib/utils.py | 24 |
2 files changed, 30 insertions, 6 deletions
diff --git a/lib/myconfig.py b/lib/myconfig.py index e1dc5b6..ba64a67 100644 --- a/lib/myconfig.py +++ b/lib/myconfig.py @@ -4,12 +4,12 @@ import os class MyConfig: ''' My Configuration ''' - m_current_epoch = { 'SegmentEpoch': 1, \ - 'GenerateEpoch': 2, \ - 'EstimateEpoch': 3, \ - 'PruneEpoch': 4, \ - 'EvaluateEpoch': 5 \ - } + m_current_epoch = {'SegmentEpoch': 1, \ + 'GenerateEpoch': 2, \ + 'EstimateEpoch': 3, \ + 'PruneEpoch': 4, \ + 'EvaluateEpoch': 5 \ + } def getSegmentEpoch(self): return m_current_epoch['SegmentEpoch'] diff --git a/lib/utils.py b/lib/utils.py new file mode 100644 index 0000000..b2e6f10 --- /dev/null +++ b/lib/utils.py @@ -0,0 +1,24 @@ +import json + +#Utils + +#File Load/Store +def read_file(infile): + with open(infile, 'r') as f: + data = ''.join(f.readlines()) + f.close() + return data + +def write_file(outfile, data): + with open(outfile, 'w') as f: + f.writelines([data]) + f.close() + return + +#JSON Load/Store +def load_status(infile): + return json.loads(read_file(infile)) + +def store_status(outfile, obj): + write_file(outfile, json.dumps(obj)) + return |