diff options
| author | yo mama <pepper@scannerjammer.com> | 2015-09-16 17:29:45 -0700 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2015-09-16 17:29:45 -0700 |
| commit | 68bfd066a588407d86d50bf384ba10f1d1a7ad88 (patch) | |
| tree | ddd1b2e8d1c45d354a4b7fbbbac839b9e1e41477 | |
| parent | 95998e066b05b6f006e2497267801e93db347717 (diff) | |
going back
| -rw-r--r-- | Param/Float/__init__.py | 5 | ||||
| -rw-r--r-- | Param/Int/__init__.py | 5 | ||||
| -rw-r--r-- | Param/__init__.py | 18 | ||||
| -rw-r--r-- | Params/__init__.py | 2 |
4 files changed, 16 insertions, 14 deletions
diff --git a/Param/Float/__init__.py b/Param/Float/__init__.py index e18fab4..eada7ac 100644 --- a/Param/Float/__init__.py +++ b/Param/Float/__init__.py @@ -9,3 +9,8 @@ def ParamFloat(Param): except Exception as e: self.err_warn("Not a float: %s" % str(value)) self.err_warn(str(e)) + def __int__(self): + return int(self.value) + + def __float__(self): + return float(self.value) diff --git a/Param/Int/__init__.py b/Param/Int/__init__.py index b7a5d32..4d52bdf 100644 --- a/Param/Int/__init__.py +++ b/Param/Int/__init__.py @@ -9,3 +9,8 @@ def ParamInt(Param): except Exception as e: self.err_warn("Not an int: %s" % str(value)) self.err_warn(str(e)) + def __int__(self): + return int(self.value) + + def __float__(self): + return float(self.value) diff --git a/Param/__init__.py b/Param/__init__.py index eececb9..80dcc0e 100644 --- a/Param/__init__.py +++ b/Param/__init__.py @@ -22,9 +22,12 @@ class Params(object): for key, value in kwargs.items(): setattr(self, key, value) - def __iter__(self): - for key, value in vars(self).iteritems(): - yield key, value + def __nonzero__(self): + return True if self.value else False + + def __str__(self): + return str(self.value) + def err_warn(self, s, error=None): self._error_log(s, error=error); @@ -40,13 +43,6 @@ class Params(object): self._log(s, error, fatal=True); sys.exit(1); - def set_val(self, key, value, value_type=None, enum_values=None): - try: - self.__setattr__(key, value) - except Exception as e: - self.err_warn("key: %s value: %s" % (key, value), error=str(e)) - - def _error_log(self, s, error=None, fatal=False): message = "ERROR - BAD PARAM" if fatal: message += "- [FATAL] -" @@ -54,5 +50,3 @@ class Params(object): if error: sys.stderr.write("PARAM ERROR: {}\n".format(str(error))) - - diff --git a/Params/__init__.py b/Params/__init__.py index 85c029d..5f098a0 100644 --- a/Params/__init__.py +++ b/Params/__init__.py @@ -46,8 +46,6 @@ class Params(object): instance = ParamFloat(d_hash[key], classname=classname) elif d_hash[key]['type'] == "img_url": instance = ParamImg_url(d_hash[key], classname=classname) - self.__setattr__(key, instance) - continue; elif d_hash[key]['type'] == "int": instance = ParamInt(d_hash[key], classname=classname) elif d_hash[key]['type'] == "json": |
