Thanks alot. I'm going to use this with few modifications to tailor it to my
needs.
Thumbs up!
> #!/usr/bin/env python
>
> ## VERSION 2
> ##
> ## changelog:
> ## - Uses inheritance from _Limited
> ## - Added _LimitedLong and llong
> ## - limit choose between int, long, and float
>
> class _Limite
#!/usr/bin/env python
## VERSION 2
##
## changelog:
## - Uses inheritance from _Limited
## - Added _LimitedLong and llong
## - limit choose between int, long, and float
class _Limited(object):
def setlimits(self, lim):
''' Set the limits and if value is not within limit,
r
On Jun 23, 1:24 am, "Josip" <[EMAIL PROTECTED]> wrote:
> > Why not make it a function?
>
> > function assignLimited(value, vmin, vmax):
> > value = max(vmin, value)
> > value = min(vmax, value)
> > return value
>
> > a = assignLimited(7, 0, 10)
>
> > Seems like it solves your problem re
On Jun 23, 1:24 am, "Josip" <[EMAIL PROTECTED]> wrote:
> > Why not make it a function?
>
> > function assignLimited(value, vmin, vmax):
> > value = max(vmin, value)
> > value = min(vmax, value)
> > return value
>
> > a = assignLimited(7, 0, 10)
>
> > Seems like it solves your problem re
> I bet you didn't even try this, unless your definition of "works"
> includes a "RuntimeError: maximum recursion depth exceeded". Here's a
> a working version:
Actually, the version I'm using is somewhat bigger. I removed docstrings and
recklessly stripped away some methods to make it shorter con
> Why not make it a function?
>
> function assignLimited(value, vmin, vmax):
> value = max(vmin, value)
> value = min(vmax, value)
> return value
>
>
> a = assignLimited(7, 0, 10)
>
>
> Seems like it solves your problem relatively cleanly.
> Note: I also removed min/max variables becaus
> Why not make it a function?
>
> function assignLimited(value, vmin, vmax):
> value = max(vmin, value)
> value = min(vmax, value)
> return value
>
>
> a = assignLimited(7, 0, 10)
>
>
> Seems like it solves your problem relatively cleanly.
> Note: I also removed min/max variables becaus
Josip wrote:
I'm trying to limit a value stored by object (either int or float):
class Limited(object):
def __init__(self, value, min, max):
self.min, self.max = min, max
self.n = value
def set_n(self,value):
if value < self.min: # boundary check
self.
On Jun 22, 5:44 am, "Josip" <[EMAIL PROTECTED]> wrote:
> I'm trying to limit a value stored by object (either int or float):
>
> class Limited(object):
> def __init__(self, value, min, max):
> self.min, self.max = min, max
> self.n = value
> def set_n(self,value):
>
> In theory you could hack Python's internal locals or globals
> dictionary so that it did something unusual while looking up your
> object. But in practice this doesn't work, because the returned
> objects (when you call globals() or locals()) attributes are readonly.
> Probably because those inte
On Sun, Jun 22, 2008 at 12:24 PM, Josip <[EMAIL PROTECTED]> wrote:
>> Not with normal vars, because = is a rebinding operator in Python,
>> rather than assignment.
>>
>> You can do (close to) the above with object properties.
>>
>> David.
>
> Yes, but it's done with built-in types like int and floa
> Not with normal vars, because = is a rebinding operator in Python,
> rather than assignment.
>
> You can do (close to) the above with object properties.
>
> David.
Yes, but it's done with built-in types like int and float. I suspect I could
subclass from them and implement limits, but I would h
On Sun, Jun 22, 2008 at 11:44 AM, Josip <[EMAIL PROTECTED]> wrote:
> I'm trying to limit a value stored by object (either int or float):
>
> class Limited(object):
>def __init__(self, value, min, max):
>self.min, self.max = min, max
>self.n = value
>def set_n(self,value):
>
13 matches
Mail list logo