I have a simple function with the following
comdList = range(0,27)
for t, in comdList:
print t
However it returns a in object not iterable error
outside the function it works fine. Whats going on??
Try this:
for t in comdList:
print t
The extra comma after the t
variable was causing the error, because of it Python thinks that the iterable is going to return a sequence of 1-tuples to unpack - for example: ((1,), (2,))
but instead it received an iterable of single elements.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.