Re: [Tutor] Pseudo-functions and dicts

2008-03-22 Thread Kent Johnson
Shrutarshi Basu wrote: > There are two solutions I've thought about: > Have a function that takes in the sensor's name as a string and > responds accordingly. (which might be what I'll end up using) That is almost the same as using ordinary dict access, with slightly different syntax, e.g. senso

Re: [Tutor] Pseudo-functions and dicts

2008-03-22 Thread Andreas Kostyrka
Well, there are basically two ways to go at it. If you want it at module level, you need to generate the functions: sensor = {'sens1': 200, 'sens2': 300} for key in sensor.keys(): def helper(keytofetch=key): return sensor[keytofetch] globals()[key] = helper print sens1() pri

[Tutor] Pseudo-functions and dicts

2008-03-21 Thread Shrutarshi Basu
I have a dictionary (in a module) which contains values of various sensors. I would like a user to be able use to a function syntax to get the sensor values, both as a whole and individually. Currently I have a function for each value who's sole purpose is to look up the corresponding dict value an