By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,351 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,351 IT Pros & Developers. It's quick & easy.

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

P: 103
I am not able to initialize empty dictionary in python33.
I have tried:
Expand|Select|Wrap|Line Numbers
  1. D=dict()
  2. D={}
Later i want to insert values using:
Expand|Select|Wrap|Line Numbers
  1. D.setdefault(num).append(ansdb2.Rname)
In both cases i am getting error "NoneType' object has no attribute 'append'"
Oct 4 '14 #1
Share this Question
Share on Google+
1 Reply

P: 103
It should be empty brackets as a second parameter to setdefault:
Expand|Select|Wrap|Line Numbers
  1. D.setdefault(num, []).append(ansdb2.Rname)
Oct 4 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.