diff options
author | Peng Wu <alexepico@gmail.com> | 2011-07-26 18:40:54 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-07-26 18:40:54 +0800 |
commit | 2575950b486c9716174a14a8b5ad8c04fa086a14 (patch) | |
tree | 8855b9414ea3607da384451f6c8d0e66740d7984 /lib/utils.py | |
parent | 04428f228cbe184618736a49fd23051301a5293a (diff) | |
download | trainer-2575950b486c9716174a14a8b5ad8c04fa086a14.tar.gz trainer-2575950b486c9716174a14a8b5ad8c04fa086a14.tar.xz trainer-2575950b486c9716174a14a8b5ad8c04fa086a14.zip |
fixes pep8 warnings
Diffstat (limited to 'lib/utils.py')
-rw-r--r-- | lib/utils.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/utils.py b/lib/utils.py index d876d67..58d31c4 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -5,15 +5,18 @@ from myconfig import MyConfig config = MyConfig() + #Exceptions class EpochError(Exception): def __init__(self, value): self.value = value + def __str__(self): return repr(self.value) #Utils + #File Load/Store/Length def read_file(infile): with open(infile, 'r') as f: @@ -21,12 +24,14 @@ def read_file(infile): f.close() return data + def write_file(outfile, data): with open(outfile, 'w') as f: f.writelines([data]) f.close() return + def get_file_length(infile): f = open(infile, 'r') f.seek(0, whence=io.SEEK_END) @@ -34,6 +39,7 @@ def get_file_length(infile): f.close() return length + #JSON Load/Store def load_status(infile): data = '{}' @@ -42,10 +48,12 @@ def load_status(infile): return json.loads(data) + def store_status(outfile, obj): write_file(outfile, json.dumps(obj)) return + def check_epoch(obj, passname): epochname = passname + 'Epoch' if not epochname in obj: @@ -54,7 +62,7 @@ def check_epoch(obj, passname): config_epoch = int(config.getEpochs()[epochname]) if object_epoch > config_epoch: raise EpochError('Un-excepted larger epoch en-countered.\n' + \ - 'Please increace the epoch in myconfig.py\n' ) + 'Please increace the epoch in myconfig.py\n') if object_epoch < config_epoch: return False @@ -62,6 +70,7 @@ def check_epoch(obj, passname): return True return None + def sign_epoch(obj, passname): epochname = passname + 'Epoch' obj[epochname] = config.getEpochs()[epochname] |