Help with List Control
#16
i'm not concerned about key names having spaces but rather the dictionary name itself.

since each system will have a varying number of events/devices, and each event/device will have a separate dictionary... i want to name the dictionary for each using the evetn/device name.

so...

devicename = "kitchen ceiling lights"

dictionary name = dict_kitchen+ceiling+lights

i'm assuming that the dictionary name cannot have spaces.

so the question is... how do i read in the devicename and assign that string text to be the name of the dictionary for that event/device?

my iniial thought is something like this but i'm not sure it would actuallty create a dictionary called 'dict_kitchen+ceiling+lights'...

item[5]='kitchen ceiling lights'
devdictname = item[5].replace(' ','+')
'dict_'+devdictname = [{'group':item[2], 'status':item[3], 'dimlevel':item[4], 'devicename':item[5], 'location':item[6], 'housecode':item[7], 'lastchange':item[8], 'devicetype':item[9], 'candim':item[10], 'values':item[11]}]
dictdevices[item[0],'dict_'+devdictname]



I'm not an expert but I play one at work.
Reply
#17
a good guide i have found for someone already familiar with programming is

http://rgruet.free.fr/pqr2.3.html

in particular it shows everything you can do with strings, lists, tuples, dictionaries...
i think slicing lists is my favorite thing about python,
i also like the powerful map, filter, reduce stuff with anonymous functions but doing that advanced junk is never very readable.
Reply
#18
(affini @ jan. 11 2006,17:36 Wrote:my iniial thought is something like this but i'm not sure it would actuallty create a dictionary called 'dict_kitchen+ceiling+lights'...

item[5]='kitchen ceiling lights'
devdictname = item[5].replace(' ','+')
'dict_'+devdictname = [{'group':item[2], 'status':item[3], 'dimlevel':item[4], 'devicename':item[5], 'location':item[6], 'housecode':item[7], 'lastchange':item[8], 'devicetype':item[9], 'candim':item[10], 'values':item[11]}]
dictdevices[item[0],'dict_'+devdictname]
sounds like you want a dictionary of dictionaries, or a dictionary of some device object.

'dict_'+devdictname = [{....

won't work since the left hand side of that assignment is a literal string, not an object (like saying 'hello world' = 4 ). you want something like

devices = {}
devices['kitchen ceiling lights'] = {'group':item[2], 'status':item[3], 'dimlevel':item[4], 'devicename':item[5], 'location':item[6], 'housecode':item[7], 'lastchange':item[8], 'devicetype':item[9], 'candim':item[10], 'values':item[11]}
or
device = hcdevice(...)
devices['kitchen ceiling lights'] = device



Reply
#19
i do want a dictionary of dictionaries... but i also want each child dictionary to be named the same as the name of the device/event.

there must be a way to do this... i have no idea how many dictionaries i will be creating so it must be dynamic.
I'm not an expert but I play one at work.
Reply
#20
the sample code line that asteron posted is exactly that.

devices['kitchen ceiling lights'] = {'group':item[2], 'status':item[3], 'dimlevel':item[4], 'devicename':item[5], 'location':item[6], 'housecode':item[7], 'lastchange':item[8], 'devicetype':item[9], 'candim':item[10], 'values':item[11]}

as it adds to devices, its creating the 'child dict' with the key name of 'kitchen ceiling lights', this removes the need to create the child dict first.

all you then need to know is that 'kitchen ceiling lights' is your key to pulling it out of devices.
Reply
#21
nice!

i'll work on it and let you guys know how it goes...
I'm not an expert but I play one at work.
Reply

Logout Mark Read Team Forum Stats Members Help
Help with List Control0