creating dictionarie names, using variables?

Fredrik Lundh fredrik at
Wed Jan 11 18:08:12 EST 2006

"Livin" 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.

if you think that you need to generate variable names, you're almost
always wrong.

> 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]

what's wrong with

    dictDevices[item[0]] = {'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]}


More information about the Python-list mailing list