The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Object is Iterable, Then Not Iterable
Discuss Object is Iterable, Then Not Iterable in the Python Programming forum on Dev Shed. Object is Iterable, Then Not Iterable Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 19th, 2013, 02:40 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 14
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
|

February 19th, 2013, 03:16 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 14
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.
|

February 19th, 2013, 03:22 PM
|
 |
Contributing User
|
|
|
|
|
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!
|

February 19th, 2013, 04:02 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 14
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?
|

February 19th, 2013, 04:53 PM
|
 |
Contributing User
|
|
|
|
>>> (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!
|

February 22nd, 2013, 10:02 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 9
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|