by reference

D

dirvine

I would like to create a dictionary based on a variable i.e read a
bunch of filenames and create a dict for each one called the filename
filename={}
to get the filenames I trraverse teh dirs woth os.path.walk or similar

Sorry I'm a bit new to python
 
M

Martin P. Hellwig

Rene said:
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:
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': {}}
>>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,283
Messages
2,571,409
Members
48,103
Latest member
MadieDeitz

Latest Threads

Top