creating dictionarie names, using variables?

Livin livin at cox.net
Wed Jan 11 20:00:53 EST 2006


Are you saying that each child dictionary actually has its own 'key', not 
just the items within it?


The goal is to create a dictionary with many dictionaries in it.
 - each child dictionary will hold a single 'device' and its related 
attributes.
 - I want to name the child dictionaries the same as their device name so it 
is easy to call them from within the dictionary.
 - also, they dictionary will be dynamic, thus the # of devices is always 
changing so they need to be created on-the-fly.




"Dan Sommers" <me at privacy.net> wrote in message 
news:m28xtmwe12.fsf at unique.fqdn...
> On Wed, 11 Jan 2006 15:53:48 -0700,
> "Livin" <livin at cox.net> wrote:
>
>> I need to dynamically create dictionary names using strings input at
>> the time of creation. These will then be placed into a "Parent"
>> dictionary.
>
> Don't do that.
>
>> 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]}]
>
> This is a list that contains one item, and that one item happens to be a
> dictionary.  Is this really what you want?
>
>> dictDevices[item[0],'dict_'+devDictName]
>
> Put the dictionaries you create into another dictionary instead:
>
> devDict = { }
>
> key = item[5].replace(' ','+')
>
> devDict[key] = {'Group':item[2],
>                'Status':item[3], # etc.
>               }
>
> HTH,
> Dan
>
> -- 
> Dan Sommers
> <http://www.tombstonezero.net/dan/> 





More information about the Python-list mailing list