Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 19th, 2013, 02:40 PM
JohnPetrucci00 JohnPetrucci00 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 14 JohnPetrucci00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 30 sec
Reputation Power: 0
Object is Iterable, Then Not Iterable

Clearly I'm confused as my code appears to iterate properly, then I receive the error:

"TypeError: 'NoneType' object is not iterable"

This is essentially what I have:

Code:
def findOriginalDBMatch(newPartDef, checkIndex, dbPartDef):

    for j in range(len(dbPartDef)):
        if dbPartDef[j].isGeometry():
            print(dbPartDef[j].getPartName())
            if newPartDef[checkIndex].getClosestMatch() == dbPartDef[j].getNameSweep1():
                return j, dbPartDef[j].getPartName()

for i in range(len(newPartDefinitions)):
    print(len(dbFullPartDefinitions))
    if newPartDefinitions[i].isGeometry():
        #print(newPartDefinitions[i].getPartName())
        matchIndex, matchName = findOriginalDBMatch(newPartDefinitions, i, dbFullPartDefinitions)


The last line with 'matchIndex, matchName' is causing the error. I am confused because the print command in the 'findOriginalDBMatch' function prints many times before the program crashes. In the function call, 'newPartDefinitions' and 'dbFullPartDefinitions' are lists of objects.

I'm at a loss right now, so please let me know what other info is helpful.

Thanks.

-John

Reply With Quote
  #2  
Old February 19th, 2013, 03:16 PM
JohnPetrucci00 JohnPetrucci00 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 14 JohnPetrucci00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 30 sec
Reputation Power: 0
I think I have figured it out - in certain cases the function did not have inputs that met criteria for it to return something. The error message seems a little confusing/misleading to me.

Reply With Quote
  #3  
Old February 19th, 2013, 03:22 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
Python functions always return something.
If you don't specify the "something" the return value is None .
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #4  
Old February 19th, 2013, 04:02 PM
JohnPetrucci00 JohnPetrucci00 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 14 JohnPetrucci00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 45 m 30 sec
Reputation Power: 0
Thanks for the response. So the "'NoneType' object" that the error message refers to actually is what is returned by the function? Is it saying it should be iterable because I am expecting the function to return multiple values?

Reply With Quote
  #5  
Old February 19th, 2013, 04:53 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
>>> (a,b,) = None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable

Quote:
Originally Posted by John
Is it saying it should be iterable because I am expecting the function to return multiple values?

Likely!

Reply With Quote
  #6  
Old February 22nd, 2013, 10:02 AM
BadOmen BadOmen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 9 BadOmen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 51 m 9 sec
Reputation Power: 0
typo

if you want a function to return multiple values, be itterable.
you have to use yield instead of return.

Code:
def testItter():
  for i in range(1,10):
    yield i

for i in testItter():
  print i

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Object is Iterable, Then Not Iterable

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap