python33, dictionary, NoneType' object has no attribute 'append'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gintare
    New Member
    • Mar 2007
    • 103

    python33, dictionary, NoneType' object has no attribute 'append'

    I am not able to initialize empty dictionary in python33.
    I have tried:
    Code:
    D=dict()
    D={}
    Later i want to insert values using:
    Code:
    D.setdefault(num).append(ansdb2.Rname)
    In both cases i am getting error "NoneType' object has no attribute 'append'"
  • gintare
    New Member
    • Mar 2007
    • 103

    #2
    It should be empty brackets as a second parameter to setdefault:
    Code:
    D.setdefault(num, []).append(ansdb2.Rname)

    Comment

    Working...