by reference

Martin P. Hellwig mhellwig at xs4all.nl
Thu Feb 9 09:08:38 EST 2006


Rene Pijlman wrote:
> dirvine:
>> I would like to create a dictionary based on a variable [...]
> 
> And what seems to be the problem?
> 
I think that this is his problem:

 >>> 'somename'={}
SyntaxError: can't assign to literal

But I'm puzzled why he wants that route, while I'm still pretty new to 
programming, I usually smell a design fault when I want to try to 
squeeze a literal name into a object variable (am I'm saying this 
correct?). Most of the time nesting dictionaries will do the trick for me:

 >>> sharedDict=dict()
 >>> sharedDict['somename']=dict()
 >>> sharedDict['someothername']=dict()
 >>> sharedDict
{'somename': {}, 'someothername': {}}
 >>>

-- 
mph



More information about the Python-list mailing list