Storing value with limits in object
i.i at i.i
Sun Jun 22 20:24:25 CEST 2008
> 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 because they would mask the
> built-in min/max functions.
Yes, the simple solution is often the best. Still, I'm going for object
oriented solution because I want the value and it's limits to be kept
together as I'll have many such values with different limits. Storing all
the limits in caller namespace is not really an option.
More information about the Python-list