NoneType object not iterable

Daniel no at no.no
Fri Jul 13 13:57:28 EDT 2007


On Fri, 13 Jul 2007 20:44:13 +0300, <tom at finland.com> wrote:

>
> Hi!
> My code is
>
>  > db = {}
>  >
>> def display():
>>     keyList = db.keys()
>>     sortedList = keyList.sort()
>>     for name in sortedList:
>>         line = 'Name: %s, Number: %s' % (name, db[name])
>>         print line.replace('\r', '')
>
> And it gives following error:
>
>>     for name in sortedList:
>> TypeError: 'NoneType' object is not iterable
>
> How can sortedList variable turn into NoneType? I just don't get it...

db is out of scope, you have to pass it to the function:
>> def display(db):
>>     keyList = db.keys()
>>     sortedList = keyList.sort()
>>     for name in sortedList:
>>         line = 'Name: %s, Number: %s' % (name, db[name])
>>         print line.replace('\r', '')


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Python-list mailing list