by reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dirvine

    #1

    by reference

    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

  • Rene Pijlman

    #2
    Re: by reference

    dirvine:[color=blue]
    >I would like to create a dictionary based on a variable [...][/color]

    And what seems to be the problem?

    --
    René Pijlman

    Comment

    • Martin P. Hellwig

      #3
      Re: by reference

      Rene Pijlman wrote:[color=blue]
      > dirvine:[color=green]
      >> I would like to create a dictionary based on a variable [...][/color]
      >
      > And what seems to be the problem?
      >[/color]
      I think that this is his problem:
      [color=blue][color=green][color=darkred]
      >>> 'somename'={}[/color][/color][/color]
      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:
      [color=blue][color=green][color=darkred]
      >>> sharedDict=dict ()
      >>> sharedDict['somename']=dict()
      >>> sharedDict['someothername']=dict()
      >>> sharedDict[/color][/color][/color]
      {'somename': {}, 'someothername' : {}}[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      --
      mph

      Comment

      Working...