Hi Mick, thanks for your mail ... although there is no reason to fear about learning python ;) - its exciting and fun ;)
well - it's just a small thing you are doing wrong ... but its very important to understand ... ;) within your loop in every iteration the loop assigns a variable "s" - on every iteration "root.find()" returns a *new* Sensor objects and the loop assigns it to the variable "s" - so in every iteration you get a *new* Sensor object assigned to "s" ... have you got the answer already ?!?! now take a look at what you actually are doing: > >>> connection = Connection ("/dev/ttyD0") > >>> for s in root.find () : print s > ... > <Sensor /10.2054A9010800/ - DS18S20> # you get a *new* "s" > <Sensor /10.522FA9010800/ - DS18S20> # you get a *new* "s" > <Sensor /28.C0617A020000/ - DS18B20> # you get a *new* "s" > <Sensor /28.F26D7A020000/ - DS18B20> # you get a *new* "s" > <Sensor /09.2179B9050000/ - DS2502> # you get a *new* "s" > >>> s.use_cache (0) # here you call the # "use_cache" method of the # last "s" - which is correct # to turn off caching for # *this* "s" ... > >>> for s in root.find () : print s > ... > <Sensor /10.2054A9010800/ - DS18S20> # but here you again get # a new Sensor object # assigned to "s" - which # has caching turned on - as # this is the default # behaviour > <Sensor /10.522FA9010800/ - DS18S20> > <Sensor /28.C0617A020000/ - DS18B20> > <Sensor /28.F26D7A020000/ - DS18B20> > <Sensor /09.2179B9050000/ - DS2502> > >>> you get the point ?!?! so as an exercise you could try to post the code ... to 1.) not get new Sensor objects in every loop ... or to 2.) get new Sensor objects and to turn off the caching before accessing their values ... ;) of course the first would be the more efficient one ... ;) if you feel to need help ... just read ahead ... for the answer ;) 1.) sensors = list (root.find ()) # generate a list of sensor objects out # of the iterator - this stores the # Sensor object in the list for s in sensors : s.use_cache (0) # on every iteration you get a different sensor ... for s in sensors : print s # but they stay the same - for every iteration this is more efficient when you are looping over the sensors more often ... 2.) for s in root.find () : s.use_cache (0) print s this is better if you only iterate once over the sensors as you save one complete iteration over the all the sensors ... and you dont need the sensor objects anymore after the iteration. well the benefit of time savings would be marginal in this case - but it's good to get used to this kind of stuff - to write code that is lean and efficient ... ;) @list: please excuse my space wasting email - but i was in the mood for it ;) regards to all, marcus. ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Owfs-developers mailing list Owfs-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/owfs-developers