Storing value with limits in object

2008-06-22 Thread Josip
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.n = self.min

Re: Storing value with limits in object

2008-06-22 Thread Josip
> 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

Re: Storing value with limits in object

2008-06-22 Thread Josip
> 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

Re: Storing value with limits in object

2008-06-22 Thread Josip
> 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

Re: Storing value with limits in object

2008-06-22 Thread Josip
> 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

Re: Storing value with limits in object

2008-06-22 Thread Josip
> 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

Re: learning unit testing in python

2008-06-23 Thread Josip
> Hi all. > > I'd like learn some basic unit testing with python. > I red some articles about different testing framework like unittest or > nose, but I'm a bit confused: what is the best choice? I'm not a > professional developer (I'm a SEO) but I belive that unit testing is a > good and pragmatic

Re: Storing value with limits in object

2008-06-26 Thread Josip
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

Re: Working with graphs - Kevin Bacon game

2019-01-09 Thread Josip Skako
Thank You for your answer, I fixed everything as You said. -- https://mail.python.org/mailman/listinfo/python-list

Re: Working with graphs - Kevin Bacon game

2019-01-09 Thread Josip Skako
Thank You for Your answer, I am not sure what to try anymore, I guess I have to return "ime" from __slots__ at cvor() class to show proper strings and I am not able to do it. Now I am not sure that I am going at right direction to do Kevin Bacon game and will I be able to load this data into gr

Re: Working with graphs - Kevin Bacon game

2019-01-09 Thread Josip Skako
I get it now, basically you are accessing class atributes with "self.something", thank You. So now I get this: "['Apollo 13 (1995)', 'Bill Paxton', 'Tom Hanks', 'Kevin Bacon\n', 'Begyndte ombord, Det (1937)', 'Aage Schmidt', 'Valso Holm\n', 'Bersaglio mobile (1967)', 'Dana Young', 'Bebe Drake\